Skip to content

Instantly share code, notes, and snippets.

@alexmccabe
Created January 22, 2018 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexmccabe/5698ac4f66d194a2cf2b698c336b3066 to your computer and use it in GitHub Desktop.
Save alexmccabe/5698ac4f66d194a2cf2b698c336b3066 to your computer and use it in GitHub Desktop.
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