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) {
e.preventDefault();
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>

DEMO

Leave a Reply

Your email address will not be published.