Menü schliessen
Created: March 18th 2021
Last updated: December 10th 2021
Categories: IT Development,  JavaScript Development
Author: Tim Fürer

JavaScript and jQuery: Smooth Scroll to element on page

Tags:  guide,  Javascript,  jQuery
Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

In this quick guide, I'll show you how to scroll to a certain element on a page with JavaScript and jQuery.

This is an alternative to the CSS property "scroll-behavior: smooth".

Advantage of this being more compability, customizability and flexability (that's a lot of -ability).

Here's the jQuery:

jQuery('html, body').animate({scrollTop: jQuery('#desired_element').offset().top}, 500);

Note that you can select the element to scroll to via classes with this method, which can prove quite useful. Also, the "500" at the end is the time to scroll in milliseconds. All in all, a very simple solution.