Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. const appScroll = () => {
  2. let latestKnownScrollY = 0,
  3. ticking = false;
  4.  
  5. const _onScroll = () => {
  6. latestKnownScrollY = window.pageYOffset;
  7. _requestTick();
  8. };
  9.  
  10. const _requestTick = () => {
  11. if (!ticking) {
  12. window.requestAnimationFrame(_update);
  13. }
  14. ticking = true;
  15. };
  16.  
  17. const _update = () => {
  18. ticking = false;
  19. const currentScrollY = latestKnownScrollY;
  20.  
  21. // Update functions here. Pass on currentScrollY as positionVariable
  22. };
  23.  
  24. // scroll mousewheel wheel
  25. window.onscroll = (e) => {
  26. _onScroll();
  27. };
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement