Skip to content

Instantly share code, notes, and snippets.

@rohmann
Created April 3, 2014 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohmann/9963871 to your computer and use it in GitHub Desktop.
Save rohmann/9963871 to your computer and use it in GitHub Desktop.
Target an a tag normally used for anchor navigation. Provide an offset element, and it can do an animated scroll and compensate for fixed headers
jQuery(function($){
$('section a').click(function(e){
e.preventDefault();
$('html,body').animate({
scrollTop: $('#' + $(this).attr('href').split("#").slice(-1)[0] ).offset().top - $('header').height()
},700 ,'swing');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment