canvas object上我可以处理什么事件.特别是,我正在寻找鼠标点击(或向下或向上等)事件,它将在画布中给出x和y.
解决方法
这里有点[
Demo].
var canvas = document.getElementById("canvas"); canvas.onclick = function(e) { // mouse coordinates relative // to the canvas element var position = canvas.getBoundingClientRect(); var click = { x: e.clientX - position.left,y: e.clientY - position.top }; };