Skip to content

Instantly share code, notes, and snippets.

Last active Jan 10, 2019
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);
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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment