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

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

    You Should try this

    var scrl
    $(window).scroll(function(){
            if($(window).scrollTop() < scrl){
                //some code while previous scroll
            }else{
                if($(window).scrollTop() > 200){
                    //scroll while downward
                }else{//scroll while downward after some specific height
                }
            }
            scrl = $(window).scrollTop();
        });
    

提交回复
热议问题