由于某些原因,控制台会继续说Uncaught TypeError:无法读取未定义的属性'clientX'
在moveCircle(script.js:5)处,但代码仍可在浏览器中使用。您能解释一下该错误如何在控制台中出现吗?
1 const CIRCLE = document.querySelector(".circle");
2 const BODY = document.body;
3
4 function moveCircle(e) {
5 CIRCLE.style.left = e.clientX + "px";
6 CIRCLE.style.top = e.clientY + "px";
7 }
8
9 BODY.addEventListener("mousemove", moveCircle, false);
10 setInterval(moveCircle, 1);
最佳答案
moveCircle
调用的函数setInterval
没有事件对象。
由事件moveCircle
触发的功能mousemove
将起作用。
为什么要通过moveCircle
呼叫setInterval
?
关于javascript - e.clientX是控制台中的未定义错误,但仍然有效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50074496/