Skip to content

Instantly share code, notes, and snippets.

@brynzovskii
Last active January 10, 2019 21:31
Show Gist options
  • Save brynzovskii/348c4a65202cd1fc34bd313132c96ab9 to your computer and use it in GitHub Desktop.
Save brynzovskii/348c4a65202cd1fc34bd313132c96ab9 to your computer and use it in GitHub Desktop.
Scroll to anchor with offset when coming from another page
jQuery(function($) {
$('a[href*="#"]:not([href="#"])').click(function() {
var target = $(this.hash);
$('html,body').stop().animate({
scrollTop: target.offset().top - 100
}, 'linear');
});
if (location.hash){
var id = $(location.hash);
}
$(window).load(function() {
if (location.hash){
$('html,body').animate({scrollTop: id.offset().top - 100}, 'linear')
};
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment