Skip to content

Instantly share code, notes, and snippets.

@hlashbrooke
Created July 12, 2013 11:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hlashbrooke/5983618 to your computer and use it in GitHub Desktop.
Save hlashbrooke/5983618 to your computer and use it in GitHub Desktop.
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