FOLLOW US
4dots Software CODE BLOG

How to scroll to any element with JQuery

To scroll to any element of the page with JQuery you have to use the animate function and set the scrollTop property to the .offset().top of the element where you want to scroll to.
For example if you want to scroll to the div with id "scrolltarget", you would have to write the following code (500 is the animation speed) :


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

TEST IT !

Here you are !!
This is an example of how to scroll to any element with JQuery.

 

Please Donate!

Please Share!