Skip to content

Instantly share code, notes, and snippets.

@navitronic
Created September 14, 2010 04:14
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 navitronic/578524 to your computer and use it in GitHub Desktop.
Save navitronic/578524 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
// Local Scroll
function filterPath(string) {
return string.replace(/^\//,'').replace(/(index|default).[a-zA-Z]{3,4}$/,'').replace(/\/$/,'');
}
$('a[href*=#]').each(function() {
if (
filterPath(location.pathname) == filterPath(this.pathname)
&& location.hostname == this.hostname
&& this.hash.replace(/#/,'')
) {
var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
if ($target) {
var targetOffset = $target.offset().top;
$(this).click(function() {
$('html, body').animate({scrollTop: targetOffset}, 400);
return false;
});
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment