mousewheel,DOMMouseScroll判断滚轮滚动方向

firefox使用DOMMouseScroll,其他浏览器使用mousewheel

首先绑定一个滚动事件

//firefox使用DOMMouseScroll,其他浏览器使用mousewheel
$(document).bind('mousewheel DOMMouseScroll',mouseScroll);

当滚动时获取wheelDelta值,firefox使用detail:值为下滚3上滚-3,其他浏览器使用wheelDelta:值为下滚-120上滚120,通过判断其值为正或者负即可判断鼠标滚轮上滚还是下滚。

function fullscreenScroll(e){
    var delta = -e.originalEvent.wheelDelta || e.originalEvent.detail;//firefox使用detail:下3上-3,其他浏览器使用wheelDelta:下-120上120//下滚
    if(delta>0){
        console.log('下滚');
    }
    //上滚
    if(delta<0){
        console.log('上滚');
    }
}

 

posted @ 2018-01-25 17:03  ysx_小鱼  阅读(253)  评论(0编辑  收藏  举报