Skip to content

Instantly share code, notes, and snippets.

@sheabunge
Created July 18, 2013 06:30
Show Gist options
  • Save sheabunge/6027099 to your computer and use it in GitHub Desktop.
Save sheabunge/6027099 to your computer and use it in GitHub Desktop.
Make anchors smoothly scroll down the page when clicked on, instead of jumping.
$(function(){
$('a[href^="\\#"]').click(function(event){
event.preventDefault();
var full_url = this.href;
var parts = full_url.split("#");
var trgt = parts[1];
var target_offset = $("#"+trgt).offset();
var target_top = target_offset.top;
$('html, body').animate({scrollTop:target_top}, 500);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment