Description
You can do this using jQuery.offset() and jQuery.animate().
Check out the jsFiddle Demonstration.
Sample
function scrollToAnchor(aid){
var aTag = $(“a[name='”+ aid +”‘]”);
$(‘html,body’).animate({scrollTop: aTag.offset().top},’slow’);
}
scrollToAnchor(‘id3’);
More Information
jsFiddle Demonstration
jQuery.offset()
jQuery.animate()
Assuming that your href attribute is linking to a div with the tag id with the same name (as usual), you can use this code:
HTML
Link to div
I’m the div
JAVASCRIPT – (Jquery)
$(“.sliding-link”).click(function(e) {
e.preventDefault();
var aid = $(this).attr(“href”);
$(‘html,body’).animate({scrollTop: $(aid).offset().top},’slow’);
});