Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. function scrollAnimated(to, duration) {
  2. var start = $(window).scrollTop(),
  3. change = to - start,
  4. currentTime = 0,
  5. increment = 20;
  6.  
  7. function easeInOut(currentTime, startValue, change, duration) {
  8. currentTime /= duration / 2;
  9.  
  10. if (currentTime < 1) {
  11. return change / 2 * currentTime * currentTime + startValue;
  12. }
  13.  
  14. currentTime--;
  15.  
  16. return -change / 2 * (currentTime * (currentTime - 2) - 1) + startValue;
  17. }
  18.  
  19. function animateScroll() {
  20. currentTime += increment;
  21.  
  22. var val = easeInOut(currentTime, start, change, duration);
  23.  
  24. $(window).scrollTop(val);
  25.  
  26. if (currentTime < duration) {
  27. setTimeout(animateScroll, increment);
  28. }
  29. }
  30.  
  31. animateScroll();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement