Skip to content

Instantly share code, notes, and snippets.

@lizardking8610
Created May 18, 2017 17:14
Show Gist options
  • Save lizardking8610/fd795c66483e0b2275701bfd560fd7a7 to your computer and use it in GitHub Desktop.
Save lizardking8610/fd795c66483e0b2275701bfd560fd7a7 to your computer and use it in GitHub Desktop.
jQuery: smooth scrolling
// Scroll to specific values
// scrollTo is the same
window.scroll({
top: 2500,
left: 0,
behavior: 'smooth'
});
// Scroll certain amounts from current position
window.scrollBy({
top: 100, // could be negative value
left: 0,
behavior: 'smooth'
});
// Scroll to a certain element
document.querySelector('.hello').scrollIntoView({
behavior: 'smooth'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment