Get mouse wheel events in jQuery?

前端 未结 14 1231
旧巷少年郎
旧巷少年郎 2020-11-22 13:26

Is there a way to get the mouse wheel events (not talking about scroll events) in jQuery?

14条回答
  •  情话喂你
    2020-11-22 13:39

    This worked for me:)

     //Firefox
     $('#elem').bind('DOMMouseScroll', function(e){
         if(e.originalEvent.detail > 0) {
             //scroll down
             console.log('Down');
         }else {
             //scroll up
             console.log('Up');
         }
    
         //prevent page fom scrolling
         return false;
     });
    
     //IE, Opera, Safari
     $('#elem').bind('mousewheel', function(e){
         if(e.originalEvent.wheelDelta < 0) {
             //scroll down
             console.log('Down');
         }else {
             //scroll up
             console.log('Up');
         }
    
         //prevent page fom scrolling
         return false;
     });
    

    from stackoverflow

提交回复
热议问题