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

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

    Why nobody use the event object returned by jQuery on scroll ?

    $window.on('scroll', function (event) {
        console.group('Scroll');
        console.info('Scroll event:', event);
        console.info('Position:', this.pageYOffset);
        console.info('Direction:', event.originalEvent.dir); // Here is the direction
        console.groupEnd();
    });
    

    I'm using chromium and I didn't checked on other browsers if they have the dir property.

提交回复
热议问题