document.addEventListener( 'mousewheel', onDocumentMouseWheel, false );
function onDocumentMouseWheel (event) {
if (event.wheelDeltaY >= 10) {
camera.position.z -= 100;
} else {
camera.position.z += 100;
}
}
感谢您的帮助!
答案 0 :(得分:0)
我有解决方案 (我不知道它是正确的方式,但它的运行)
在渲染功能(更新)
中if (Mouse.moving && Mouse.speed > 0) {
Mouse.speed -= Mouse.maxSpeed / 20;
Mouse.smooth();
}
鼠标对象:
var Mouse = {
moving: false,
movingForward: null,
speed: 60,
timeOfSmooth: 2000, // maxTimeOfSmooth
wheelListener: function () {
_this = this;
_this.maxSpeed = _this.speed; // set maxSpeed
document.addEventListener( 'mousewheel', onDocumentMouseWheel, false );
function onDocumentMouseWheel (event) {
_this.speed = _this.maxSpeed;
_this.moving = true;
if (event.wheelDeltaY >= 10) {
_this.movingForward = true;
} else {
_this.movingForward = false;
}
clearTimeout(_this.timeOut);
_this.timeOut = setTimeout(function () {
_this.moving = false;
}, _this.timeOfSmooth);
}
},
smooth: function () {
if (this.moving) {
if (_this.movingForward) {
Engine.camera.position.z -= _this.speed;
} else {
Engine.camera.position.z += _this.speed;
}
}
},
init: function () {
this.wheelListener();
}
};