Scroll to DIV by ID without jQuery

Use scrollIntoView instead of jQuery animate.

Dicembre 16, 2022

There is the method scrollIntoView which is compatible with all modern browser

document.getElementById("scrollhere").scrollIntoView(
   {behaviour:'smooth',
    block:'start'
);

So there is no need to still use this jQuery snippet:

$('html,body').animate({
	scrollTop: $("#scrollhere").offset().top
},'slow');

Behaviour works also with scrollTo.

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.