How can I determine the direction of a jQuery scroll event?

后端 未结 25 1493
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-21 22:24

I\'m looking for something to this effect:

$(window).scroll(function(event){
   if (/* magic code*/ ){
       // upscroll code
   } else {
      // downscrol         


        
25条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 23:05

    Since bind has been deprecated on v3 ("superseded by on") and wheel is now supported, forget wheelDelta:

    $(window).on('wheel', function(e) {
      if (e.originalEvent.deltaY > 0) {
        console.log('down');
      } else {
        console.log('up');
      }
      if (e.originalEvent.deltaX > 0) {
        console.log('right');
      } else {
        console.log('left');
      }
    });
    
    

提交回复
热议问题