gpt4 book ai didi

javascript - 我可以处理 Canvas 对象上的哪些事件?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:38:04 25 4
gpt4 key购买 nike

关于 canvas object 的事件我能处理的。特别是,我正在寻找一个鼠标点击(或向下、向上等)事件,它会给我 Canvas 内的 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
};
};

关于javascript - 我可以处理 Canvas 对象上的哪些事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4235813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com