真实鼠标在画布中的位置
function createImageOnCanvas(imageId){ document.getElementById("imgCanvas").style.display = "block"; document.getElementById("images").style.overflowY= "hidden"; var canvas = document.getElementById("imgCanvas"); var context = canvas.getContext("2d"); var img = new Image(300,300); img.src = document.getElementById(imageId).src; context.drawImage(img, (0),(0));}function draw(e){ var canvas = document.getElementById("imgCanvas"); var context = canvas.getContext("2d"); posx = e.clientX; posy = e.clientY; context.fillStyle = "#000000"; context.fillRect (posx, posy, 4, 4);}
HTML部分
<body> <div id="images"> </div> <canvas onmousemove="draw(event)" style="margin:0;padding:0;" id="imgCanvas" class="canvasView" width="250" height="250"></canvas>
相关分类