JSFiddle - React, Tailwind, and code Playground

by holden321

HTML

<button>top</button>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>

CSS

div {height: 100px; background: gray;}

JavaScript

function scrollToBottom(to,duration) {
    if (duration <= 0) return;
    var difference = document.documentElement.scrollHeight - window.scrollY;
    var perTick = difference / duration * 10;

    setTimeout(function() {
        window.scroll(0, window.scrollY - perTick);
        scrollToBottom(duration - 10);
    }, 10);
}

scrollToBottom(1000)