window.scrollTo with options not working on Microsoft Edge

CDK picture CDK · Sep 11, 2018 · Viewed 27.4k times · Source

I have a strange issue which I can only replicate on Microsoft browsers (Edge and IE11 tested).

This code correctly scrolls the window 1000px to the left and down, with a smooth behaviour in Chrome and Firefox. However, on Edge and IE, it does not move at all.

Answer

eyecatchUp picture eyecatchUp · Mar 18, 2019

As mentioned before, the Scroll Behavior specification has only been implemented in Chrome, Firefox and Opera.

Here's a one-liner to detect support for the behavior property in ScrollOptions:

const supportsNativeSmoothScroll = 'scrollBehavior' in document.documentElement.style;

And here's a simple implementation for cross-browser smooth scrolling: https://nicegist.github.io/d210786daa23fd57db59634dd231f341