我没有找到专门解决的IE7模式版本。我尝试了各种版本,在Chrome,FF,IE9 +中运行良好,但在强制IE7模式下不在IE11中,客户端服务器设置要求:-(。
IE7模式警告“mousewheel”作为wheelEvent,但是甚至从不在鼠标滚轮上调用scrollHandler()的第一个警报行,所以似乎没有通过window.attachEvent附加事件/处理程序?
var wheelEvent = "onwheel" in document.createElement("div") ? "wheel" : // Modern browsers support "wheel"
document.onmousewheel !== undefined ? "mousewheel" : // Webkit and IE support at least "mousewheel"
"DOMMouseScroll"; // let's assume that remaining browsers are older Firefox
function scrollHandler(wheelEvent) {
alert("scrollHandler "+wheelEvent);
//upDown = -1 on scroll-down, = 1 on scroll up
if (wheelEvent.wheelDelta) {//chrome
upDown = (wheelEvent.wheelDelta % 120 - 0) == -0 ? wheelEvent.wheelDelta / 120 : wheelEvent.wheelDelta / 12;
} else {//FF
var rawAmmount = wheelEvent.deltaY ? wheelEvent.deltaY : wheelEvent.detail;
upDown = -(rawAmmount % 3 ? rawAmmount * 10 : rawAmmount / 3);
}
scroller(upDown);
}
if (window.addEventListener) {//most browsers
window.addEventListener(wheelEvent, scrollHandler );
}else if (window.attachEvent){//IE7...
alert("IE7 - window.attachEvent: " + wheelEvent);
window.attachEvent(wheelEvent, scrollHandler);
}
答案 0 :(得分:0)
attachEvent对事件使用"" 前缀,因此您需要将代码更改为,并且需要将事件附加到文档而不是窗口。
else if (window.attachEvent){//IE7...
alert("IE7 - window.attachEvent: " + wheelEvent);
document.attachEvent("on"+wheelEvent, scrollHandler);
}