title: Javascript to keep a webpage scrolling, scroll down slowly, wait, back to top
body: <p>I need a javascript on a webpage that I want to display on a local quiz. The page shows the score table, but with 60 teams, I cannot show them all at once. So I want to add a javascript to the page that slowly scrolls down, and when the page is at the bottom, it should wait 2 seconds then jump back to the page top and start scrolling down again.</p>
  
  <p>At <a href="https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_scrollto" rel="nofollow noreferrer">https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_scrollto</a> I used this script:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;style&gt;
  body {
      width: 500px;
  }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body onLoad="pageScroll()"&gt;
  
  &lt;h1&gt;Scores&lt;/h1&gt;
  
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  test test test &lt;br&gt;
  
  &lt;script&gt;
  
  function pageScroll() {
       window.scrollBy(0,10); // horizontal and vertical scroll increments
       scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds
              if ((window.innerHeight + window.pageYOffset) &gt;= document.body.offsetHeight) {
            scrolldelay = setTimeout('PageUp()',2000);
        }
  
  }
  
  function PageUp() {
   window.scrollTo(0, 0);
  }
  
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The scrolling speed will be altered, this is too fast but just for testing. The script seems to do the job, but when jumping to the top of the page, there are some "hickups" before scrolling down again. Can anyone please tell me what's wrong?</p>