Scroll Function Firing Multiple Times Instead of Once

前端 未结 2 1522
一向
一向 2021-01-06 01:59

I am trying to create a website that automatically scrolls to each section upon a single scroll action. This means that the code has to check if the page is scrolled up or s

2条回答
  •  遥遥无期
    2021-01-06 03:00

    This worked for me!

    var ScrollDebounce = true;
    $('.class').on('scroll',
    function () {
    if (ScrollDebounce) {
    ScrollDebounce = false;
    
    //do stuff    
    
    setTimeout(function () { ScrollDebounce = true; }, 500);
    }
    })
    

提交回复
热议问题