用jQuery将页面制作为简单画板

$( function () {
$(document) .on( 'mousedown', function ( e) {
var e = e || window.event;
$(document) .on( 'mousemove', function ( e) {
var e = e || window.event;
var x = e.pageX;
var y = e.pageY;
$( '<div></div>') .css({
'position': 'absolute',
'width': '5px',
'height': '5px',
'borderRadius': '50%',
'left': x, 'top': y })
.appendTo( 'body'); $( 'div') .css( 'background',
function Color() {
var r = parseInt( Math .random() * 256);
var g = parseInt( Math .random() * 256);
var b = parseInt( Math .random() * 256);
return "rgb(" + r + ',' + g + ',' + b + ")";
});
})
$(document) .on( 'mouseup', function () {
$(document) .off( 'mousemove') .off( 'mouseup');
})
})
})

猜你喜欢

转载自blog.csdn.net/weixin_41912152/article/details/80778672