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?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With