[removed] do an action after user is done scrolling

后端 未结 5 1927
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 06:55

I\'m trying to figure out a way to do this. I have a list of boxes, each about 150px high. I am using javascript (and jquery) and want that, after a user scroll

5条回答
  •  春和景丽
    2020-12-01 07:33

    The code:

    var scrollTimeout = null;
    var scrollendDelay = 500; // ms
    
    $(window).scroll(function() {
        if ( scrollTimeout === null ) {
            scrollbeginHandler();
        } else {
            clearTimeout( scrollTimeout );
        }
        scrollTimeout = setTimeout( scrollendHandler, scrollendDelay );
    });
    
    function scrollbeginHandler() {
        // this code executes on "scrollbegin"
        document.body.style.backgroundColor = "yellow";
    }
    
    function scrollendHandler() {
        // this code executes on "scrollend"
        document.body.style.backgroundColor = "gray";
        scrollTimeout = null;
    }
    

提交回复
热议问题