Last active
August 29, 2015 14:18
-
-
Save funkjedi/5820170bc0c7642a4cb4 to your computer and use it in GitHub Desktop.
Scroll to anchor
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
// Handle links with href started with '#' only. | |
jQuery(document).on('click', 'a[href]', function(e) { | |
// target element id | |
var id = jQuery(this).attr('href'); | |
if (!id.match(/^#/) || jQuery(id).length === 0 || jQuery(this).hasClass('ui-tabs-anchor')) { | |
return; | |
} | |
// prevent standard hash navigation (avoid blinking in IE) | |
e.preventDefault(); | |
// top position relative to the document | |
var pos = Math.max(0, jQuery(id).offset().top - 100); | |
// animated top scrolling | |
jQuery('html,body').animate({ scrollTop: pos }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment