Skip to content

Instantly share code, notes, and snippets.

@brynzovskii
Last active Jan 10, 2019
Embed
What would you like to do?
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