Created
August 5, 2019 07:58
-
-
Save zhongdeliu/2a478bf7d3214b0bc099b16258b0b91b to your computer and use it in GitHub Desktop.
Detect if scroll() takes ScrollToOptions
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
var isSmoothScrollSupported = 'scrollBehavior' in document.documentElement.style; | |
var scrollToOptions = { | |
top: 100, | |
left: 100, | |
behavior: 'smooth' | |
}; | |
if (isSmoothScrollSupported) { | |
// Native smooth scrolling | |
window.scroll(scrollToOptions); | |
} else { | |
// Old way scrolling without effects | |
window.scroll(scrollToOptions.left, scrollToOptions.top); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment