gpt4 book ai didi

JavaScript 事件监听器 mousemove

转载 作者:行者123 更新时间:2023-12-03 02:23:50 26 4
gpt4 key购买 nike

u如何记录鼠标坐标的值?

div = document.querySelector('.div');

div.addEventListener('mousemove', function yo(u) {
console.log(u);
});

这会记录鼠标的 x 和 y 坐标值。

最佳答案

根据 this API引用:

document.addEventListener(事件、函数、useCapture)

是函数原型(prototype),它接受事件类型字符串作为第一个参数,“回调”函数作为第二个参数,第三个参数 true 或 false 指示应在哪个阶段调用该函数。

当回调激活时,事件对象被传递给声明的函数,其类型取决于回调的类型。

在“mousemove”的情况下,网络浏览器传递给函数的参数包含各种有用的 information

根据this Mozilla 开发人员引用,在较新版本的 firefox 和 chrome 中,console.log 函数仅存储对传递到 Web 浏览器的对象的引用“这不一定是您调用 console.log 时对象的“值” (),但它是您单击打开时对象的值。”

所有非全局值都将相对于 .div

希望这有帮助。

关于JavaScript 事件监听器 mousemove,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49040861/

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