Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know Scroll event has finished with jQuery [duplicate]

Possible Duplicate:
Javascript: do an action after user is done scrolling

the Scroll event fires when the user starts scrolling the page, right? How to know if he is finished then? I want to call a function after the scrolling has done. Does anyone has any idea?

Thanks!

P.S. With jQuery please, but pure JS is also okay.

like image 750
Mahdi Avatar asked Sep 24 '12 11:09

Mahdi


People also ask

How do I know if I have scroll reached end?

scrollTop - elem. clientHeight; It calculates distance scroll bar to bottom of element. Equal 0, if scroll bar has reached bottom.

What is scroll event in jQuery?

The scroll event occurs when the user scrolls in the specified element. The scroll event works for all scrollable elements and the window object (browser window). The scroll() method triggers the scroll event, or attaches a function to run when a scroll event occurs.


1 Answers

You can achieve this using setTimeout. you can change timeout (im using 100) value according to your requirement.

var timeoutId;
$(selector).scroll(function(){
  if(timeoutId ){
         clearTimeout(timeoutId );  
  }
  timeoutId = setTimeout(function(){
   // your code 
  }, 100);

});
like image 99
Anoop Avatar answered Nov 04 '22 19:11

Anoop