Skip to content

Instantly share code, notes, and snippets.

@funkjedi
Last active August 29, 2015 14:18
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 funkjedi/5820170bc0c7642a4cb4 to your computer and use it in GitHub Desktop.
Save funkjedi/5820170bc0c7642a4cb4 to your computer and use it in GitHub Desktop.
Scroll to anchor
// 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