softpcapps Software CODE HELP BLOG

Shareware and free Open Source Windows Software Applications and free Online Tools

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);


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