Advertisement
DailyJapaneseThread

Autoscrolling HTML

Mar 4th, 2016
2,214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <script>
  5. /**** Fun Stuff that you need to copy into your page ****/
  6. document.addEventListener("DOMNodeInserted", function () {
  7. var LEEWAY = 200; // Amount of "leeway" pixels before latching onto the bottom.
  8.  
  9. // Some obscene browser shit because making sense is for dweebs
  10. var b = document.body;
  11. var offset = b.scrollHeight - b.offsetHeight;
  12. var scrollPos = (b.scrollTop+offset);
  13. var scrollBottom = (b.scrollHeight - (b.clientHeight+offset));
  14.  
  15. // If we are at the bottom, go to the bottom again.
  16. if (scrollPos >= scrollBottom - LEEWAY) {
  17. window.scrollTo(0,document.body.scrollHeight);
  18. }
  19.  
  20. }, false);
  21. /**** End of the Fun Stuff ****/
  22. </script>
  23. </head>
  24.  
  25.  
  26. <body>
  27.  
  28.  
  29. </body>
  30.  
  31.  
  32.  
  33. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement