Get mouse wheel events in jQuery?

前端 未结 14 1212
旧巷少年郎
旧巷少年郎 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:50

    As of now in 2017, you can just write

    $(window).on('wheel', function(event){
    
      // deltaY obviously records vertical scroll, deltaX and deltaZ exist too
      if(event.originalEvent.deltaY < 0){
        // wheeled up
      }
      else {
        // wheeled down
      }
    });
    

    Works with current Firefox 51, Chrome 56, IE9+

提交回复
热议问题