mercredi 8 décembre 2021

How to get the timing of scrollbar stopped?

I am trying to change web background when stop scrolling page.
When I starting to scroll, it will get depth, and start the timer interval.
interval detect a new depth called tmp per second.
if interval equals tmp, switch my background.

interval = null;    //stop scrolling timer
var tmp;    //old position
var depth;  //new position
funtion isScrollEnd(){
    tmp = document.documentElement.scrollTop || document.body.scrollTop;
    if(tmp == depth){
        alert("NO PARKING HERE!");
    }
};
window.addEventListener('scroll', function(){
    depth = document.documentElement.scrollTop || document.body.scrollTop;
    if(interval == null)
        interval = setInterval("isScrollEnd()", 1000); //1s in each detect
});

if you have any solution, please help




Aucun commentaire:

Enregistrer un commentaire