Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(window)
- {
- var isScrolling = true,
- body = document.body,
- $stopScrollBtn = document.createElement('div'),
- scrollDelay = .2;
- function applyStyles(element, styles)
- {
- for(var rule in styles)
- {
- if(styles.hasOwnProperty(rule))
- {
- element.style[rule] = styles[rule];
- }
- }
- }
- applyStyles($stopScrollBtn, {
- display : 'inline-block',
- position : 'fixed',
- top : '10px',
- right : '10px',
- zIndex : 100000000,
- backfaceVisibility: 'hidden',
- color : 'white',
- backgroundColor : 'red',
- padding : '10px 20px',
- borderRadius : '5px',
- fontSize : '20px',
- fontFamily : 'Helvetica, sans-serif',
- cursor : 'pointer'
- });
- $stopScrollBtn.innerHTML = 'Stop Auto-scroll';
- body.appendChild($stopScrollBtn);
- var interval = window.setInterval(scrollToBottom, scrollDelay * 1000);
- function scrollToBottom()
- {
- if(isScrolling)
- {
- window.scroll(0, body.offsetHeight);
- }
- }
- function stopAutoScroll()
- {
- isScrolling = false;
- window.clearInterval(interval);
- body.removeChild($stopScrollBtn);
- }
- $stopScrollBtn.addEventListener('click', stopAutoScroll);
- //window.addEventListener('mousewheel', function(event)
- //{
- // if(Math.abs(event.deltaY) > 15)
- // {
- // if(isScrolling)
- // {
- // stopAutoScroll();
- // }
- // }
- //});
- })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement