Created
May 18, 2017 17:14
-
-
Save lizardking8610/fd795c66483e0b2275701bfd560fd7a7 to your computer and use it in GitHub Desktop.
jQuery: smooth scrolling
This file contains hidden or 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
// 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