/*===============自定义画板*/
function initpaint( canvas ){
var obj = canvas.getContext(‘2d‘);
canvas.onmousedown = function( e ){ //鼠标按下的时候
var mx = e.layerX;
var my = e.layerY;
obj.moveTo( mx, my);
canvas.onmousemove = function( e ){ //鼠标移动的时候
var endx = e.layerX;
var endy = e.layerY;
obj.lineTo( endx, endy);
obj.stroke();
};
canvas.onmouseup = function( e ){ //鼠标松开的时候
canvas.onmousemove = null;
canvas.onmouseup = null;
};
};
};
时间: 2024-10-24 22:47:21