5

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.

Community
  • 1
  • 1
Mahdi
  • 9,247
  • 9
  • 53
  • 74
  • No. A `scroll` event fires every time the page has moved a single pixel. Check out [fire scroll event only once per second](http://stackoverflow.com/q/9613594/1048572) – Bergi Sep 24 '12 at 12:01
  • @FrançoisWahl I don't want to use $.doTimeout – Mahdi Sep 24 '12 at 12:02
  • @Bergi thanks, but do you have any reference for that? It seems that it just fires when you start scrolling and not continuously ... – Mahdi Sep 24 '12 at 12:03
  • http://stackoverflow.com/a/4289550/612202 then take this one – dan-lee Sep 24 '12 at 12:04
  • @Mahdi: Don't think you get around it. Any solution will most likely contain timeout code. – Nope Sep 24 '12 at 12:04
  • @Mahdi: Um, yes, not for literally every pixel but for every scroll move (3 lines?). If you don't want to use the plugin, you can will still need to program its functionality – Bergi Sep 24 '12 at 12:05
  • @FrançoisWahl oh no, there should be something ... :( – Mahdi Sep 24 '12 at 12:06
  • @Bergi I want to know if there is any native and original event for that, not tricks ... – Mahdi Sep 24 '12 at 12:07
  • @DanLee I KNOW they timeouts are native in JS, I mean a native EVENT ... but it seems, there is no event, thanks! no need to be angry ... – Mahdi Sep 24 '12 at 12:11

1 Answers1

8

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);

});
Anoop
  • 23,044
  • 10
  • 62
  • 76