Last active
January 10, 2019 21:31
-
-
Save brynzovskii/348c4a65202cd1fc34bd313132c96ab9 to your computer and use it in GitHub Desktop.
Scroll to anchor with offset when coming from another page
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
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