Created
July 27, 2014 14:02
-
-
Save mertenvg/fcd075236b0229d14832 to your computer and use it in GitHub Desktop.
Scroll to anchor with same name as current page. Uses jQuery.
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
/* | |
* Scroll to page section if it exists, but delay for a bit first. | |
*/ | |
var page = location.href.replace(/^.+?\/?([^\/]+)$/i, '$1') | |
, delay = 500 | |
, offset = -50 | |
, $anchor; | |
if (page && ($anchor = $('a[name="'+page+'"]')).length) { | |
$('html,body').delay(delay).animate({scrollTop: $anchor.offset().top + offset}, 'slow'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment