Venciity

JS scrollbar

Jul 7th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function runScroll() {
  2.   scrollTo(document.querySelector("#store-menu-component"), 0, 600);
  3. }
  4.  
  5. var scrollme;
  6. scrollme = document.querySelector("#next");
  7. scrollme.addEventListener("click",runScroll,false)
  8.  
  9. function scrollTo(element, to, duration) {
  10.   if (duration <= 0)
  11.   {
  12.     return;
  13.   }
  14.  
  15.   var difference = to - element.scrollTop;
  16.   var perTick = difference / duration * 10;
  17.  
  18.   setTimeout(function() {
  19.     element.scrollTop = element.scrollTop + perTick;
  20.     if (element.scrollTop == to)
  21.     {
  22.         return;
  23.     }
  24.    
  25.     scrollTo(element, to, duration - 10);
  26.   }, 10);
  27. }
Add Comment
Please, Sign In to add comment