 <p>The reason your progressbar doesn't come back to the same position is this:</p> <pre><code>if (scroll &lt;= 28) { progressbar.style.top = "30px"; } </code></pre> <p>You are telling it that once you scroll, if the distance from the top is less than 28px it should go to 30px from the top while it starts at 0. Even if you start by scrolling 1px down it'll jump to 30px.</p>