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

后端 未结 25 1490
爱一瞬间的悲伤
爱一瞬间的悲伤 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:13

    You can determin mousewhell direction.

    $(window).on('mousewheel DOMMouseScroll', function (e) {
        var delta = e.originalEvent.wheelDelta ? 
                       e.originalEvent.wheelDelta : -e.originalEvent.detail;
    
        if (delta >= 0) {
            console.log('scroll up');
        } else {
            console.log('scroll down');
        }
    });
    

提交回复
热议问题