判断鼠标滚轮的滚动方向

function mousewheelHandler(e){
var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
console.log(delta > 0 ? "向上滚动" : "向下滚动");
}
 
//for Firefox
document.addEventListener("DOMMouseScroll", mousewheelHandler, false);
 
//for Chrome Safari
document.addEventListener("mousewheel", mousewheelHandler, false);
posted @ 2016-09-30 11:06  lanyan  阅读(1333)  评论(0编辑  收藏  举报