code_junkie

Best way to manage costly scrolling in JavaScript?

Nov 12th, 2011
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. // need to have this variable outside the scope of the handler defined below
  2. var timeoutId = null;
  3.  
  4. // think of "connect" as pseudocode for whatever you use to connect handlers
  5. connect(widget, "onscroll", function() {
  6. // ...scrolling...
  7. if(timeoutId != null) clearTimeout(timeoutId);
  8. timeoutId = setTimeout(function() {
  9. // *probably* done scrolling, it has been
  10. // 1 second since the last scroll...
  11. // run your code to render current position here
  12. }, 1000);
  13. });
Add Comment
Please, Sign In to add comment