Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple animated scroll for jQuery
function scrollToElement( target ) {
var topoffset = 30;
var speed = 800;
var destination = jQuery( target ).offset().top - topoffset;
jQuery( 'html:not(:animated),body:not(:animated)' ).animate( { scrollTop: destination}, speed, function() {
window.location.hash = target;
});
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment