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

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

    This is simple and easy detection for when the user scrolls away from the top of the page and for when they return to the top.

    $(window).scroll(function() {
        if($(window).scrollTop() > 0) {
            // User has scrolled
        } else {
            // User at top of page
        }
    });
    

提交回复
热议问题