Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery Scroll To Anchor
jQuery( document ).ready(function(){
jQuery( 'a[href^="#"]' ).each(function(){
if ( jQuery( this ).attr( 'href' ).length > 1 ) {
if ( jQuery( 'body' ).find( jQuery( this ).attr( 'href' ) ) ) {
jQuery( this ).click( function(e){
e.preventDefault();
jQuery( 'html, body' ).animate({
scrollTop: jQuery( jQuery( this ).attr( 'href' ) ).offset().top
}, 'slow' );
});
}
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.