Created
July 18, 2013 06:30
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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