Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.scrollTo with options not working on Microsoft Edge

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

<style>
    body {
        height: 5000px;
        width: 5000px;
    }
</style>
<p>Click the button to scroll the document window to 1000 pixels.</p>
<button onclick="scrollWin()">Click me to scroll!</button>
<script>
    function scrollWin() {
        window.scrollTo({
            left: 1000, 
            top: 1000,
            behavior:"smooth"
        });
    }
</script>

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.

like image 935
CDK Avatar asked Sep 11 '18 12:09

CDK


People also ask

Why scroll is not working in Edge?

Locate your profiles and click on Settings. Uncheck the Make scroll wheel scroll window under cursor option. Some users confirmed this fixed the issue and allowed them to keep using X-Mouse without breaking other mouse capabilities.

How to Enable Smooth scrolling on mouse?

Step 1: Type in chrome://flags/#smooth-scrolling in Chrome's address bar and press Enter. Step 2: To turn the feature off, click on the disable link. Then, click on a restart button to complete the process.

How do I scroll in Microsoft edge?

You can toggle the settings under “Roll the mouse wheel to scroll” to “One screen at a time” or “Multiple lines at a time”. Open Microsoft Edge. In the address bar type edge://flags. In the search box at the top, type Microsoft Edge scrolling personality.


1 Answers

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://gist.github.com/eyecatchup/d210786daa23fd57db59634dd231f341

like image 93
eyecatchUp Avatar answered Oct 01 '22 20:10

eyecatchUp