Shenglian / -WORK_TIP

工作上小技巧
4 stars 1 forks source link

[js] Detecting when a visitor has stopped scrolling with vanilla Javascript #164

Open Shenglian opened 5 years ago

Shenglian commented 5 years ago
// Setup isScrolling variable
var isScrolling;

// Listen for scroll events
window.addEventListener('scroll', function ( event ) {

    // Clear our timeout throughout the scroll
    window.clearTimeout( isScrolling );

    // Set a timeout to run after scrolling ends
    isScrolling = setTimeout(function() {

        // Run the callback
        console.log( 'Scrolling has stopped.' );

    }, 66);

}, false);
Shenglian commented 5 years ago

source form : https://gomakethings.com/detecting-when-a-visitor-has-stopped-scrolling-with-vanilla-javascript/