Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. var autoScroll = function() {
  2.  
  3. var speed = 0;
  4. var scrollDir = 'down';
  5. var viewport = window.innerHeight;
  6. var bottom = document.body.scrollHeight;
  7.  
  8. var getSpeed = function() {
  9. speed = prompt("Please Enter a Scroll Speed");
  10. scrollMove();
  11. stopButton();
  12. };
  13.  
  14. var stopButton = function() {
  15. scrolling = true;
  16. var stop = document.createElement('button');
  17. stop.innerText = 'Stop Scroll';
  18. stop.style.position = 'fixed';
  19. stop.style.top = 0;
  20. stop.style.left = 0;
  21. stop.onclick = function() {
  22. if (scrolling) {
  23. clearTimeout(scrolldelay);
  24. scrolling = false;
  25. stop.innerText = 'Start Scroll';
  26. }
  27. else {
  28. speed = prompt("Please Enter a Scroll Speed");
  29. scrollMove();
  30. scrolling = true;
  31. stop.innerText = 'Stop Scroll';
  32. }
  33. };
  34. document.body.appendChild(stop);
  35. };
  36.  
  37.  
  38. var scrollMove = function() {
  39. if (scrollDir === 'down') {
  40. window.scrollBy(0,speed);
  41. scrolldelay = setTimeout(scrollMove,10);
  42. }
  43. if (scrollDir ==='up') {
  44. window.scrollBy(0,-speed);
  45. scrolldelay = setTimeout(scrollMove,10);
  46. }
  47. var sp = document.body.scrollTop;
  48. if (sp + viewport === bottom) {
  49. scrollDir = 'up';
  50. }
  51. if (sp === 0) {
  52. scrollDir = 'down';
  53. }
  54. };
  55. getSpeed();
  56. };
  57.  
  58. autoScroll();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement