鼠标拖动绘制矩形框(canvas); CanvasExt = { drawRect:function(canvasId,penColor,strokeWidth){ ; that.penColor=penColor; that.penWidth=strokeWidth; document.getElementById(canvasId); canvas.getBoundingClientRect(); canvasRect.left; canvasRect.top; layer; ; ; ; (e){ that.penColor; that.penWidth; layerIndex++; layer++; layerName+=layerIndex; x canvasLeft; y canvasTop; $(canvasId).addLayer({ type: , strokeStyle: color, strokeWidth: penWidth, name:layerName, fromCenter: false, x: x, y: y, width: 1, height: 1 }); $(canvasId).drawLayers(); $(canvasId).saveCanvas(); (e){ width x; height y; $(canvasId).removeLayer(layerName); $(canvasId).addLayer({ type: , strokeStyle: color, strokeWidth: penWidth, name:layerName, fromCenter: false, x: x, y: y, width: width, height: height }); $(canvasId).drawLayers(); } }; canvas.onmouseup=function(e){ that.penColor; that.penWidth; canvas.onmousemove=null; width x; height y; $(canvasId).removeLayer(layerName); $(canvasId).addLayer({ type: , strokeStyle: color, strokeWidth: penWidth, name:layerName, fromCenter: false, x: x, y: y, width: width, height: height }); $(canvasId).drawLayers(); $(canvasId).saveCanvas(); } } }; drawPen(); function drawPen(){ ; ; CanvasExt.drawRect(,color,width); }