'Browser native scroll function: how to check compatibility
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?
Solution 1:[1]
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);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Maksym Petrenko |