Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(window)
  2. {
  3.  
  4.     var isScrolling = true,
  5.         body = document.body,
  6.         $stopScrollBtn = document.createElement('div'),
  7.         scrollDelay = .2;
  8.  
  9.     function applyStyles(element, styles)
  10.     {
  11.         for(var rule in styles)
  12.         {
  13.             if(styles.hasOwnProperty(rule))
  14.             {
  15.                 element.style[rule] = styles[rule];
  16.             }
  17.         }
  18.     }
  19.  
  20.     applyStyles($stopScrollBtn, {
  21.         display           : 'inline-block',
  22.         position          : 'fixed',
  23.         top               : '10px',
  24.         right             : '10px',
  25.         zIndex            : 100000000,
  26.         backfaceVisibility: 'hidden',
  27.         color             : 'white',
  28.         backgroundColor   : 'red',
  29.         padding           : '10px 20px',
  30.         borderRadius      : '5px',
  31.         fontSize          : '20px',
  32.         fontFamily        : 'Helvetica, sans-serif',
  33.         cursor            : 'pointer'
  34.     });
  35.  
  36.     $stopScrollBtn.innerHTML = 'Stop Auto-scroll';
  37.  
  38.     body.appendChild($stopScrollBtn);
  39.  
  40.     var interval = window.setInterval(scrollToBottom, scrollDelay * 1000);
  41.  
  42.     function scrollToBottom()
  43.     {
  44.         if(isScrolling)
  45.         {
  46.             window.scroll(0, body.offsetHeight);
  47.         }
  48.     }
  49.  
  50.     function stopAutoScroll()
  51.     {
  52.         isScrolling = false;
  53.         window.clearInterval(interval);
  54.         body.removeChild($stopScrollBtn);
  55.     }
  56.  
  57.     $stopScrollBtn.addEventListener('click', stopAutoScroll);
  58.     //window.addEventListener('mousewheel', function(event)
  59.     //{
  60.     //  if(Math.abs(event.deltaY) > 15)
  61.     //  {
  62.     //      if(isScrolling)
  63.     //      {
  64.     //          stopAutoScroll();
  65.     //      }
  66.     //  }
  67.     //});
  68.  
  69. })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement