Reputation:
I'm trying to test whether or not a browser supports the scrollBy behaviour smooth.
I have the following which works for the most part but some IOS Safari versions are reporting true when they don't actually support it. I'm assuming that they do this because they support Behaviour just not Smooth Behaviour. Is there a way to test specifically for smooth behaviour? Or perhaps I'm doing something wrong in my try that's giving the false positive?
Here is my current code:
function testSmoothScroll() {
let support = false;
try {
wrapper.scrollIntoView({
get behavior() {
support = true;
}
});
} catch (err) {
// Error catching
}
return support;
}
Upvotes: 2
Views: 919
Reputation: 89294
You can check if the scrollBehavior
property is supported by checking the style of the HTML element.
const smoothScrollSupported = 'scrollBehavior' in document.documentElement.style;
Upvotes: 3