How to do animated scroll window to top or offset of particular element

Whenever you want to do animated scroll using a particular html element as a offset you can use the following jQuery code where -100 it the offset from the element in pixels.

jQuery('html, body').animate({scrollTop:jQuery('#someid').offset().top -100}, 'slow');

Also if you would like to have the option for scrolling to the toп of your page use this one:

jQuery('html,body').animate({ scrollTop: 0 }, 'slow');

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *