我有幾個事件監聽器,它適用於所有瀏覽器,除了Firefox中的鼠標滾輪(在Chrome和其他版本中都是完美的)。滾動時,它應該放大和縮小。這是JSC3D庫。代碼如下帶鼠標滾輪的addEventListener在Firefox中不起作用
// setup input handlers.
// compatibility for touch devices is taken into account
var self = this;
if(!JSC3D.PlatformInfo.isTouchDevice) {
this.canvas.addEventListener('mousedown', function(e){self.mouseDownHandler(e);}, false);
this.canvas.addEventListener('mouseup', function(e){self.mouseUpHandler(e);}, false);
this.canvas.addEventListener('mousemove', function(e){self.mouseMoveHandler(e);}, false);
//this.canvas.addEventListener('mousewheel', function(e){self.mouseWheelHandler(e);}, false);
this.canvas.addEventListener(JSC3D.PlatformInfo.browser == 'firefox' ? 'DOMMouseScroll' : 'mousewheel',
function(e){self.mouseWheelHandler(e);}, false);
document.addEventListener('keydown', function(e){self.keyDownHandler(e);}, false);
document.addEventListener('keyup', function(e){self.keyUpHandler(e);}, false);
}
else if(JSC3D.Hammer) {
JSC3D.Hammer(this.canvas).on('touch release hold drag pinch', function(e){self.gestureHandler(e);});
}
else {
this.canvas.addEventListener('touchstart', function(e){self.touchStartHandler(e);}, false);
this.canvas.addEventListener('touchend', function(e){self.touchEndHandler(e);}, false);
this.canvas.addEventListener('touchmove', function(e){self.touchMoveHandler(e);}, false);
}
和功能JSC3D.Viewer.prototype.mouseWheelHandler
JSC3D.Viewer.prototype.mouseWheelHandler = function(e) {
if(!this.isLoaded)
return;
if(this.onmousewheel) {
var info = this.pick(e.clientX, e.clientY);
this.onmousewheel(info.canvasX, info.canvasY, e.button, info.depth, info.mesh);
}
e.preventDefault();
e.stopPropagation();
if(!this.isDefaultInputHandlerEnabled)
return;
this.zoomFactor *= (JSC3D.PlatformInfo.browser == 'firefox' ? -e.detail : e.wheelDelta) < 0 ? 1.1 : 0.91;
this.update();
};
有人嗎?
查看wheel事件 - https://developer.mozilla.org/en-US/docs/Web/Events/wheel - DOMMouseScroll是**老** firefox - 鏈接頁面有跨瀏覽器代碼示例 –
我累了替換DOMMouseScroll與輪子仍然不起作用 – Megadevice
你說'不工作'這是沒有意義的...是事件發生了嗎?你至少有你的'mouseWheelHandler'函數嗎? –