Skip to content

Instantly share code, notes, and snippets.

@jgoslow
Last active August 13, 2022 18:00
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 jgoslow/6eb7b17025f02395c94f0b83f30af069 to your computer and use it in GitHub Desktop.
Save jgoslow/6eb7b17025f02395c94f0b83f30af069 to your computer and use it in GitHub Desktop.
JS Scrolling functions
function scrollToDiv(target) {
var loc = $(target).offset();
jQuery("html,body").animate({
scrollTop: loc.top-150//,
//scrollLeft: loc.left
});
return false;
}
function scrollToDiv(elem, scrollOffset=80) {
window.scroll({
behavior: 'smooth',
left: 0,
top: elem.offsetTop - scrollOffset
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment