Created
January 22, 2018 10:32
-
-
Save alexmccabe/5698ac4f66d194a2cf2b698c336b3066 to your computer and use it in GitHub Desktop.
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
function scrollIntoView($element) { | |
var scrollTop = 0; | |
if ($element.length) { | |
scrollTop = $element.offset().top - | |
$('#headerwrap')[0].clientHeight - 40; | |
window.scrollTo(0, scrollTop); | |
} | |
} | |
$(document).on('ready', function () { | |
if (window.location.hash) { | |
var hash = window.location.hash; | |
var $element = $(hash); | |
setTimeout(function() { | |
scrollIntoView($element); | |
}, 1000); | |
} | |
$('[data-scrollto]').on('click', function (event) { | |
event.preventDefault(); | |
scrollIntoView($($(this).attr('href'))); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment