Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. // Reference: http://www.html5rocks.com/en/tutorials/speed/animations/
  2.  
  3. var last_known_scroll_position = 0;
  4. var ticking = false;
  5.  
  6. function doSomething(scroll_pos) {
  7. // do something with the scroll position
  8. }
  9.  
  10. window.addEventListener('scroll', function(e) {
  11. last_known_scroll_position = window.scrollY;
  12. if (!ticking) {
  13. window.requestAnimationFrame(function() {
  14. doSomething(last_known_scroll_position);
  15. ticking = false;
  16. });
  17. }
  18. ticking = true;
  19. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement