我试图在我的构造函数中使用一个名为_mouseoverdistancebool
的全局变量来注意鼠标何时位于distance
中名为threejs
的对象3D上。但价值永远不会改变。
这是影响变量的代码:
constructor(targetMesh, controls, camera, container) {
super();
this._mouseoverdistancebool = false;
this.addEventListeners();
}
addEventListeners() {
this._distance.addEventListener('mouseleave', this.mouseleavedistance);
this._distance.addEventListener('mouseenter', this.mouseenterdistance);
this._container.addEventListener('mousewheel', this.onMove);
this._container.addEventListener('DOMMouseScroll', this.onMove);
}
mouseenterdistance(evt) {
console.log("Mouse over the object!!!");
this._mouseoverdistancebool = true;
}
mouseleavedistance(evt) {
console.log("Mouse leaves the object....");
this._mouseoverdistancebool = false;
}
onMove(evt) {
console.log(this._mouseoverdistancebool);
}
所以我在调试中可以看到事件运行良好但布尔值总是为假。像这样:
>Mouse over the object!!!
>false
>Mouse leaves the object....
>false
我是javascript中构造函数的新手......我做错了什么?