Smooth scroll to anchor working in all browsers

To scroll smoothly to an anchor on your webpage with jQuery, you can use following snippet:

$(".anchor").click(function(e) {
anchor = $(this).attr('href');
$("html, body").animate({
'scrollTop': $(anchor).offset().top
}, 1000);

This works for anchors like

<a class="anchor" href="#div1">click</a>

<div id="div1">texttext</div>


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.