我有一些事件侦听器,它适用于除 Firefox 中的鼠标滚轮之外的所有浏览器(在 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.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();
};
任何人?