Skip to content

Instantly share code, notes, and snippets.

@zhongdeliu
Created August 5, 2019 07:58
Show Gist options
  • Save zhongdeliu/2a478bf7d3214b0bc099b16258b0b91b to your computer and use it in GitHub Desktop.
Save zhongdeliu/2a478bf7d3214b0bc099b16258b0b91b to your computer and use it in GitHub Desktop.
Detect if scroll() takes ScrollToOptions
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