码迷,mamicode.com
首页 > 其他好文 > 详细

mousewheel,DOMMouseScroll判断滚轮滚动方向

时间:2018-01-25 17:19:49      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:方向   滚动   鼠标   func   color   event   nal   cti   ons   

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(上滚);
    }
}

 

mousewheel,DOMMouseScroll判断滚轮滚动方向

标签:方向   滚动   鼠标   func   color   event   nal   cti   ons   

原文地址:https://www.cnblogs.com/ysx215/p/8352118.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!