function drawImg(Sp) { var startX, startY; canvas.onclick = function(e) { e = window.event || e; startX = e.pageX - this.offsetLeft; startY = e.pageY - this.offsetTop; if(Sp === 'square'){ var square = Draw.drawSquare(startX, startY); square.draw(); } }}/*用对象来模拟类*/var Draw = { 'drawSquare': function(startX, startY) { var squareObj = {}; squareObj.x = startX; squareObj.y = startY; squareObj.draw = function() { ctx.beginPath(); ctx.strokeRect(startX, startY, 50, 50); ctx.strokeStyle = '#000'; } squareObj.onmouseover = function() { ctx.style.cursor = 'move'; } return squareObj; }}想了好多种方法都想不出来,哪位大佬可以帮帮忙呀。就是鼠标点击画布的时候,会出现一个正方形,然后如果鼠标移上去的话,是可以移动的,会出现移动的那个形状。
添加回答
举报
0/150
提交
取消