Reputation: 1025
The function scroll in "most" browsers can be used, but it seems that it can be "overloaded". From the compatibility tab, you'll see that some browsers support
element.scroll(scrollToOptions)
whereas others only support
element.scroll(x, y)
How can I check which method is supported (despite it having the same name) in the current browser?
Upvotes: 4
Views: 1405
Reputation: 1063
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);
}
Upvotes: 7