January 21, 2020

Easiest JQuery smooth scroll

The most minimalist way to include smooth scroll in JQuery after an on_click event is triggered. I specifically integrated this in my website.

function go_top() {
    window.scrollTo({
        top: 0,
        behavior: 'smooth'
    });
}

function go_bottom() {
    window.scrollTo({
        top: document.body.scrollHeight,
        behavior: 'smooth'
    });
}
<a onclick="go_top()">Back to top</a>
<a onclick="go_bottom()">Go to bottom</a>
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket