Luc
Luc

Reputation: 1825

detect when page is being scrolled

What I want: - I want to detect when a user is scrolling the page. Not once, but every single time. - When user stopped scrolling, something must happen.

What I DONT want: detect when the page is scrolled to a certain point(so no waypoints.js).

A solution that I've tried at first:

$(window).scroll(function() {
    console.log("page scrolled");
});

Problem is, he fires the console.log way too many times. So maybe I need some sort of delay, but I don't know how to fix that properly.

Hope someone of you can help!

Upvotes: 0

Views: 151

Answers (1)

Rakesh Kumar
Rakesh Kumar

Reputation: 2855

Try this solution to fire alert when page stop scrolling.

code

var timer;
$(window).on('scroll',function () {
    clearTimeout(timer);
    timer = setTimeout( scrollStop , 150 );
});
var scrollStop = function () { 
    // do stuff
    alert('Scrolling Stop'); 
};

Fiddle Demo

Reference post

Upvotes: 2

Related Questions