Javascript 带有鼠标滚轮的addEventListener不';我不能在Firefox中工作

Javascript 带有鼠标滚轮的addEventListener不';我不能在Firefox中工作,javascript,javascript-events,stl,jsc3d,Javascript,Javascript Events,Stl,Jsc3d,我有一些事件监听器,除了Firefox中的mousewheel(在Chrome和其他浏览器中,它工作得非常完美),它可以在所有浏览器中工作。当我滚动时,它应该放大和缩小。这是JSC3D库。代码如下 // setup input handlers. // compatibility for touch devices is taken into account var self = this; if(!JSC3D.PlatformInfo.isTouchDevice) { this.can

我有一些事件监听器,除了Firefox中的mousewheel(在Chrome和其他浏览器中,它工作得非常完美),它可以在所有浏览器中工作。当我滚动时,它应该放大和缩小。这是JSC3D库。代码如下

// 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.mouseweelHandler

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();
};
JSC3D.Viewer.prototype.mouseweelHandler=函数(e){
如果(!this.isLoaded)
返回;
如果(此.onmousewheel){
var info=this.pick(e.clientX,e.clientY);
这个.onmouseheel(info.canvasX,info.canvasY,e.button,info.depth,info.mesh);
}
e、 预防默认值();
e、 停止传播();
如果(!this.isDefaultInputHandlerEnabled)
返回;
this.zoomFactor*=(JSC3D.PlatformInfo.browser=='firefox'?-e.detail:e.wheelDelta)<0?1.1:0.91;
这个.update();
};
有人吗?

if(this.addEventListener){
//IE9、Chrome、Safari、Opera
此.addEventListener(“mousewheel”,MouseWheelHandler,false);
//火狐
此.addEventListener(“DOMMouseScroll”,MouseWheelHandler,false);
}
//IE 6/7/8

否则,这个.attachEvent(“onmouseheel”,鼠标轮处理器)最尊重jsc3d,但与其嗅探浏览器代理,不如对此进行功能检测,比如:

if(!JSC3D.PlatformInfo.isTouchDevice) {
...
this.canvas.addEventListener('onwheel' in document ? 'wheel' : 'onmousewheel' in document ? 'mousewheel' : 'DOMMouseScroll', function(e){self.mouseWheelHandler(e);});
...
}
编辑: …并且使用相同的逻辑,还可以在以下位置删除对“firefox”的检查:

JSC3D.Viewer.prototype.mouseWheelHandler = function(e) {
...
    this.zoomFactor *= (e.deltaY ? e.deltaY : e.wheelDelta ? e.wheelDelta : e.detail) < 0 ? 1.1 : 0.91;
...
};
在最新的FF中测试,文档中的“onwheel”返回true


请让我知道这是否解决了问题。

请参阅wheel事件-DOMMouseScroll是旧的firefox-链接页面有跨浏览器代码示例我累了,用wheel替换DOMMouseScroll仍然不起作用你说
不起作用
,这毫无意义。。。事件是否已启动?你至少可以使用你的
mouseWheelHandler
功能吗?看起来DOMMouseScroll在旧版本的Firefox中使用过
function OnViewerMouseWheeel(canvasX, canvasY, button, depth, mesh) {
    ...
}
viewer.onmousewheel=OnViewerMouseWheeel;