这个事件在标准下和IE下是有区别的。
firefox是按标准实现的,事件名为"DOMMouseScroll ",IE下采用的则是"mousewheel "。
当然一行代码就解决了兼容问题
var mousewheel = document.all? "mousewheel": "DOMMouseScroll";
var mousewheel = document.all? "mousewheel": "DOMMouseScroll";
事件属性,IE是
event.wheelDelta,Firefox是
event.detail 属性的方向值也不一样,IE向上滚 > 0,Firefox向下滚 > 0。
使用插件
Mouse Wheel Extension 3.0.2
jQuery(
function
($) {
$( ' div.mousewheel_example ' )
.bind( ' mousewheel ' , function (event, delta) {
var dir = delta > 0 ? ' Up ' : ' Down ' ,
vel = Math.abs(delta);
$(this).text(dir + ' at a velocity of ' + vel);
return false ;
});
});
$( ' div.mousewheel_example ' )
.bind( ' mousewheel ' , function (event, delta) {
var dir = delta > 0 ? ' Up ' : ' Down ' ,
vel = Math.abs(delta);
$(this).text(dir + ' at a velocity of ' + vel);
return false ;
});
});