window.scrollTo with options not working on Microsoft Edgeelement.scrollIntoView(scrollIntoViewOptions) in Safari and IE always scrolls to the top instead of centerScrollIntoView Alternative for Safari/iPhoneHow do JavaScript closures work?jQuery get specific option tag textHow does JavaScript .prototype work?How does data binding work in AngularJS?Microsoft Edge - keydown eventcss alignment issues in Microsoft Edge browserWheel event in Microsoft EdgejQuery onclick not working in browser Edgewindow.open() parameters not working in EdgeVertical scrollbar not appearing in ssrs report in edge browser when uploaded in dynamics crm 365

Alternative to sending password over mail?

What killed these X2 caps?

Would Slavery Reparations be considered Bills of Attainder and hence Illegal?

Took a trip to a parallel universe, need help deciphering

Can one be a co-translator of a book, if he does not know the language that the book is translated into?

Could gravitational lensing be used to protect a spaceship from a laser?

How can I tell someone that I want to be his or her friend?

Intersection of two sorted vectors in C++

Assassin's bullet with mercury

Is it inappropriate for a student to attend their mentor's dissertation defense?

How could indestructible materials be used in power generation?

Why is Collection not simply treated as Collection<?>

Where does SFDX store details about scratch orgs?

Will google still index a page if I use a $_SESSION variable?

Has there ever been an airliner design involving reducing generator load by installing solar panels?

Today is the Center

Can a rocket refuel on Mars from water?

1960's book about a plague that kills all white people

What do you call someone who asks many questions?

Why are electrically insulating heatsinks so rare? Is it just cost?

I would say: "You are another teacher", but she is a woman and I am a man

I Accidentally Deleted a Stock Terminal Theme

Forgetting the musical notes while performing in concert

Blender 2.8 I can't see vertices, edges or faces in edit mode



window.scrollTo with options not working on Microsoft Edge


element.scrollIntoView(scrollIntoViewOptions) in Safari and IE always scrolls to the top instead of centerScrollIntoView Alternative for Safari/iPhoneHow do JavaScript closures work?jQuery get specific option tag textHow does JavaScript .prototype work?How does data binding work in AngularJS?Microsoft Edge - keydown eventcss alignment issues in Microsoft Edge browserWheel event in Microsoft EdgejQuery onclick not working in browser Edgewindow.open() parameters not working in EdgeVertical scrollbar not appearing in ssrs report in edge browser when uploaded in dynamics crm 365






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















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.










share|improve this question






















  • window.scrollTo(1000,1000); is the original signatire. I assume Edge and IE did not change that but I might be wrong since MDN says they implemented this

    – mplungjan
    Sep 11 '18 at 12:46












  • according to MDN, the (options) variant has always existed in all browsers

    – Jaromanda X
    Sep 11 '18 at 12:50











  • Known bug: developer.microsoft.com/en-us/microsoft-edge/platform/issues/…

    – mplungjan
    Sep 11 '18 at 12:54












  • @mplungjan - you are correct, and if I just use window.scrollTo(1000,1000); it does scroll (obviously not smoothly) - but as @Jaromanda X says, MDN suggests the options should be supported by all browsers: developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo

    – CDK
    Sep 11 '18 at 12:55











  • @JaromandaX that is incorrect. It is for sure a new variant - I cannot get scrollTo(1000,1000) to work in Edge either

    – mplungjan
    Sep 11 '18 at 12:56

















0















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.










share|improve this question






















  • window.scrollTo(1000,1000); is the original signatire. I assume Edge and IE did not change that but I might be wrong since MDN says they implemented this

    – mplungjan
    Sep 11 '18 at 12:46












  • according to MDN, the (options) variant has always existed in all browsers

    – Jaromanda X
    Sep 11 '18 at 12:50











  • Known bug: developer.microsoft.com/en-us/microsoft-edge/platform/issues/…

    – mplungjan
    Sep 11 '18 at 12:54












  • @mplungjan - you are correct, and if I just use window.scrollTo(1000,1000); it does scroll (obviously not smoothly) - but as @Jaromanda X says, MDN suggests the options should be supported by all browsers: developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo

    – CDK
    Sep 11 '18 at 12:55











  • @JaromandaX that is incorrect. It is for sure a new variant - I cannot get scrollTo(1000,1000) to work in Edge either

    – mplungjan
    Sep 11 '18 at 12:56













0












0








0








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.










share|improve this question














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.






<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>





<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>






javascript microsoft-edge






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 11 '18 at 12:40









CDKCDK

100111




100111












  • window.scrollTo(1000,1000); is the original signatire. I assume Edge and IE did not change that but I might be wrong since MDN says they implemented this

    – mplungjan
    Sep 11 '18 at 12:46












  • according to MDN, the (options) variant has always existed in all browsers

    – Jaromanda X
    Sep 11 '18 at 12:50











  • Known bug: developer.microsoft.com/en-us/microsoft-edge/platform/issues/…

    – mplungjan
    Sep 11 '18 at 12:54












  • @mplungjan - you are correct, and if I just use window.scrollTo(1000,1000); it does scroll (obviously not smoothly) - but as @Jaromanda X says, MDN suggests the options should be supported by all browsers: developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo

    – CDK
    Sep 11 '18 at 12:55











  • @JaromandaX that is incorrect. It is for sure a new variant - I cannot get scrollTo(1000,1000) to work in Edge either

    – mplungjan
    Sep 11 '18 at 12:56

















  • window.scrollTo(1000,1000); is the original signatire. I assume Edge and IE did not change that but I might be wrong since MDN says they implemented this

    – mplungjan
    Sep 11 '18 at 12:46












  • according to MDN, the (options) variant has always existed in all browsers

    – Jaromanda X
    Sep 11 '18 at 12:50











  • Known bug: developer.microsoft.com/en-us/microsoft-edge/platform/issues/…

    – mplungjan
    Sep 11 '18 at 12:54












  • @mplungjan - you are correct, and if I just use window.scrollTo(1000,1000); it does scroll (obviously not smoothly) - but as @Jaromanda X says, MDN suggests the options should be supported by all browsers: developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo

    – CDK
    Sep 11 '18 at 12:55











  • @JaromandaX that is incorrect. It is for sure a new variant - I cannot get scrollTo(1000,1000) to work in Edge either

    – mplungjan
    Sep 11 '18 at 12:56
















window.scrollTo(1000,1000); is the original signatire. I assume Edge and IE did not change that but I might be wrong since MDN says they implemented this

– mplungjan
Sep 11 '18 at 12:46






window.scrollTo(1000,1000); is the original signatire. I assume Edge and IE did not change that but I might be wrong since MDN says they implemented this

– mplungjan
Sep 11 '18 at 12:46














according to MDN, the (options) variant has always existed in all browsers

– Jaromanda X
Sep 11 '18 at 12:50





according to MDN, the (options) variant has always existed in all browsers

– Jaromanda X
Sep 11 '18 at 12:50













Known bug: developer.microsoft.com/en-us/microsoft-edge/platform/issues/…

– mplungjan
Sep 11 '18 at 12:54






Known bug: developer.microsoft.com/en-us/microsoft-edge/platform/issues/…

– mplungjan
Sep 11 '18 at 12:54














@mplungjan - you are correct, and if I just use window.scrollTo(1000,1000); it does scroll (obviously not smoothly) - but as @Jaromanda X says, MDN suggests the options should be supported by all browsers: developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo

– CDK
Sep 11 '18 at 12:55





@mplungjan - you are correct, and if I just use window.scrollTo(1000,1000); it does scroll (obviously not smoothly) - but as @Jaromanda X says, MDN suggests the options should be supported by all browsers: developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo

– CDK
Sep 11 '18 at 12:55













@JaromandaX that is incorrect. It is for sure a new variant - I cannot get scrollTo(1000,1000) to work in Edge either

– mplungjan
Sep 11 '18 at 12:56





@JaromandaX that is incorrect. It is for sure a new variant - I cannot get scrollTo(1000,1000) to work in Edge either

– mplungjan
Sep 11 '18 at 12:56












6 Answers
6






active

oldest

votes


















3














Maybe not a true answer in the sense of the word, but I have solved this problem by using this helpful polyfill: https://github.com/iamdustan/smoothscroll which works really well across all browsers.



Example page for pollyfill: http://iamdustan.com/smoothscroll/



Many thanks to the author.






share|improve this answer






























    2














    You can detect support for the behavior option in scrollTo using this snippet:



    function testSupportsSmoothScroll () 
    var supports = false
    try
    var div = document.createElement('div')
    div.scrollTo(
    top: 0,
    get behavior ()
    supports = true
    return 'smooth'

    )
    catch (err)
    return supports



    Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly. If supports is false, you fall back to a polyfill.






    share|improve this answer























    • This question makes me feel more and more stupid ;-). Great idea, I don't know how I could miss it, when I use the same every day for testing addEventListener's options...

      – Kaiido
      Jan 25 at 8:44











    • Wouldn't be const supportsNativeSmoothScroll = 'scrollBehavior' in document.documentElement.style; much easier? (Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly.)

      – eyecatchUp
      Mar 18 at 11:42


















    2














    Indeed, they don't support this variant, MDN articles should be updated.



    One way to polyfill this method is to run the scroll method in a requestAnimationFrame powered loop. Nothing too fancy here.



    The main problem that arises is how to detect when this variant is not supported. actually @nlawson's answer tackles this problem perfectly...



    For this, we can use the fact that a call to Window#scroll will fire a ScrollEvent if the viewPort actually did scroll.

    This means we can set up an asynchronous test that will:



    1. Attach an event handler to the ScrollEvent,

    2. Call a first time scroll(left , top) variant to be sure the Event will fire,

    3. Overwrite this call with a second one using the options variant.

    4. In the event handler, if we aren't at the correct scroll position, this means we need to attach our polyfill.

    So the caveat of this test is that it is an asynchronous test. But since you need to actually wait for the document has loaded before calling this method, I guess in 99% of cases it will be ok.



    Now to less burden the main doc, and since it is already an asynchronous test, we can even wrap this test inside an iframe, which gives us something like:



    /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
    (function ScrollPolyfill()

    // The asynchronous tester

    // wrapped in an iframe (will not work in SO's StackSnippet®)
    var iframe = document.createElement('iframe');
    iframe.onload = function()
    var win = iframe.contentWindow;
    // listen for a scroll event
    win.addEventListener('scroll', function handler(e)
    // when the scroll event fires, check that we did move
    if(win.pageXOffset < 99) // !== 0 should be enough, but better be safe
    attachPolyfill();

    // cleanup
    document.body.removeChild(iframe);
    );
    // set up our document so we can scroll
    var body = win.document.body;
    body.style.width = body.style.height = '1000px';

    win.scrollTo(10, 0); // force the event
    win.scrollTo(left:100, behavior:'instant'); // the one we actually test
    ;
    // prepare our frame
    iframe.src = "about:blank";
    iframe.setAttribute('width', 1);
    iframe.setAttribute('height', 1);
    iframe.setAttribute('style', 'position:absolute;z-index:-1');
    iframe.onerror = function()
    console.error('failed to load the frame, try in jsfiddle');
    ;
    document.body.appendChild(iframe);

    // The Polyfill

    function attachPolyfill()
    var original = window.scroll, // keep the original method around
    animating = false, // will keep our timer's id
    dx = 0,
    dy = 0,
    target = null;

    // override our methods
    window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;

    // going nowhere
    if(!dx && !dy)
    return;

    // save passed arguments
    target = opts;
    // save the rAF id
    animating = anim();

    ;
    // the animation loop
    function anim()

    )();




    Sorry for not providing a runable demo inside the answer directly, but StackSnippet®'s over-protected iframes don't allow us to access the content of an inner iframe on IE...
    So instead, here is a link to a jsfiddle.




    Post-scriptum:
    Now comes to my mind that it might actually be possible to check for support in a synchronous way by checking for the CSS scroll-behavior support, but I'm not sure it really covers all UAs in the history...




    Post-Post-scriptum:
    Using @nlawson's detection we can now have a working snippet ;-)






    /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
    (function ScrollPolyfill()

    // The synchronous tester from @nlawson's answer
    var supports = false
    test_el = document.createElement('div'),
    test_opts = top:0;
    // ES5 style for IE
    Object.defineProperty(test_opts, 'behavior',
    get: function()
    supports = true;

    );
    try
    test_el.scrollTo(test_opts);
    catch(e);

    if(!supports)
    attachPolyfill();


    function attachPolyfill()
    var original = window.scroll, // keep the original method around
    animating = false, // will keep our timer's id
    dx = 0,
    dy = 0,
    target = null;

    // override our methods
    window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;
    dy = (opts.top - window.pageYOffset) ;
    // the animation loop
    function anim()

    )();

    // OP's code,
    // by the time you click the button, the polyfill should already be set up if needed
    function scrollWin()
    window.scrollTo(
    left: 1000,
    top: 1000,
    behavior: 'smooth'
    );

    body 
    height: 5000px;
    width: 5000px;

    <p>Click the button to scroll the document window to 1000 pixels.</p>
    <button onclick="scrollWin()">Click me to scroll!</button>








    share|improve this answer

























    • Wow, this is an in depth answer for creating a polyfill from scratch. I checked it and it works well, but will stick with the simpler polyfill that avoids iframes linked from my own answer. Thanks for providing this though!

      – CDK
      Sep 14 '18 at 12:05






    • 1





      @CDK han.... of course someone already did it, bettter... Feel a bit stupid now to have wrote this in the first place without I saw your answer... Note that you can accept your own answer, which is not a bad one. And I see they used the idea I had in my Ps for detection, so it might be reliable enough after all...

      – Kaiido
      Sep 14 '18 at 12:26


















    2














    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






    share|improve this answer
































      0














      Unfortunately, there is no way for that method to work in these two browsers.
      You can check open issues here and see that they have done nothing on this issue.
      https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/15534521/






      share|improve this answer























      • Already posted in a comment

        – mplungjan
        Sep 11 '18 at 12:56


















      0














      You can try to use Element.ScrollLeft and Element.ScrollTop property with Window.scrollTo().



      Below is the example which is working with Edge and other browsers.






      <html>
      <style>
      body
      height: 5000px;
      width: 5000px;

      </style>
      <p>Click the button to scroll the document window to 1000 pixels.</p>
      <button onclick="scrollWin(this)">Click me to scroll!</button>
      <script>
      function scrollWin(pos)
      window.scrollTo(pos.offsetTop+1000,pos.offsetLeft+1000);



      </script>
      </html>





      Smooth behavior is not working with this code.



      Reference:



      Element.scrollLeft



      Element.scrollTop



      Regards



      Deepak






      share|improve this answer























      • Thanks @deepak - but the main reason I wanted to use scrollTo with the options was for the smooth scroll affect. Appreciate your answer though.

        – CDK
        Sep 13 '18 at 15:13











      • @ CDK, I again made a several tests with smooth behavior with Edge. But this behavior is not working. so at present, It looks like this behavior is not supported with Edge.

        – Deepak-MSFT
        Sep 14 '18 at 1:46











      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52276194%2fwindow-scrollto-with-options-not-working-on-microsoft-edge%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      Maybe not a true answer in the sense of the word, but I have solved this problem by using this helpful polyfill: https://github.com/iamdustan/smoothscroll which works really well across all browsers.



      Example page for pollyfill: http://iamdustan.com/smoothscroll/



      Many thanks to the author.






      share|improve this answer



























        3














        Maybe not a true answer in the sense of the word, but I have solved this problem by using this helpful polyfill: https://github.com/iamdustan/smoothscroll which works really well across all browsers.



        Example page for pollyfill: http://iamdustan.com/smoothscroll/



        Many thanks to the author.






        share|improve this answer

























          3












          3








          3







          Maybe not a true answer in the sense of the word, but I have solved this problem by using this helpful polyfill: https://github.com/iamdustan/smoothscroll which works really well across all browsers.



          Example page for pollyfill: http://iamdustan.com/smoothscroll/



          Many thanks to the author.






          share|improve this answer













          Maybe not a true answer in the sense of the word, but I have solved this problem by using this helpful polyfill: https://github.com/iamdustan/smoothscroll which works really well across all browsers.



          Example page for pollyfill: http://iamdustan.com/smoothscroll/



          Many thanks to the author.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 11 '18 at 13:38









          CDKCDK

          100111




          100111























              2














              You can detect support for the behavior option in scrollTo using this snippet:



              function testSupportsSmoothScroll () 
              var supports = false
              try
              var div = document.createElement('div')
              div.scrollTo(
              top: 0,
              get behavior ()
              supports = true
              return 'smooth'

              )
              catch (err)
              return supports



              Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly. If supports is false, you fall back to a polyfill.






              share|improve this answer























              • This question makes me feel more and more stupid ;-). Great idea, I don't know how I could miss it, when I use the same every day for testing addEventListener's options...

                – Kaiido
                Jan 25 at 8:44











              • Wouldn't be const supportsNativeSmoothScroll = 'scrollBehavior' in document.documentElement.style; much easier? (Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly.)

                – eyecatchUp
                Mar 18 at 11:42















              2














              You can detect support for the behavior option in scrollTo using this snippet:



              function testSupportsSmoothScroll () 
              var supports = false
              try
              var div = document.createElement('div')
              div.scrollTo(
              top: 0,
              get behavior ()
              supports = true
              return 'smooth'

              )
              catch (err)
              return supports



              Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly. If supports is false, you fall back to a polyfill.






              share|improve this answer























              • This question makes me feel more and more stupid ;-). Great idea, I don't know how I could miss it, when I use the same every day for testing addEventListener's options...

                – Kaiido
                Jan 25 at 8:44











              • Wouldn't be const supportsNativeSmoothScroll = 'scrollBehavior' in document.documentElement.style; much easier? (Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly.)

                – eyecatchUp
                Mar 18 at 11:42













              2












              2








              2







              You can detect support for the behavior option in scrollTo using this snippet:



              function testSupportsSmoothScroll () 
              var supports = false
              try
              var div = document.createElement('div')
              div.scrollTo(
              top: 0,
              get behavior ()
              supports = true
              return 'smooth'

              )
              catch (err)
              return supports



              Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly. If supports is false, you fall back to a polyfill.






              share|improve this answer













              You can detect support for the behavior option in scrollTo using this snippet:



              function testSupportsSmoothScroll () 
              var supports = false
              try
              var div = document.createElement('div')
              div.scrollTo(
              top: 0,
              get behavior ()
              supports = true
              return 'smooth'

              )
              catch (err)
              return supports



              Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly. If supports is false, you fall back to a polyfill.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Dec 7 '18 at 15:52









              nlawsonnlawson

              10.1k12343




              10.1k12343












              • This question makes me feel more and more stupid ;-). Great idea, I don't know how I could miss it, when I use the same every day for testing addEventListener's options...

                – Kaiido
                Jan 25 at 8:44











              • Wouldn't be const supportsNativeSmoothScroll = 'scrollBehavior' in document.documentElement.style; much easier? (Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly.)

                – eyecatchUp
                Mar 18 at 11:42

















              • This question makes me feel more and more stupid ;-). Great idea, I don't know how I could miss it, when I use the same every day for testing addEventListener's options...

                – Kaiido
                Jan 25 at 8:44











              • Wouldn't be const supportsNativeSmoothScroll = 'scrollBehavior' in document.documentElement.style; much easier? (Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly.)

                – eyecatchUp
                Mar 18 at 11:42
















              This question makes me feel more and more stupid ;-). Great idea, I don't know how I could miss it, when I use the same every day for testing addEventListener's options...

              – Kaiido
              Jan 25 at 8:44





              This question makes me feel more and more stupid ;-). Great idea, I don't know how I could miss it, when I use the same every day for testing addEventListener's options...

              – Kaiido
              Jan 25 at 8:44













              Wouldn't be const supportsNativeSmoothScroll = 'scrollBehavior' in document.documentElement.style; much easier? (Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly.)

              – eyecatchUp
              Mar 18 at 11:42





              Wouldn't be const supportsNativeSmoothScroll = 'scrollBehavior' in document.documentElement.style; much easier? (Tested in Chrome, Firefox, Safari, and Edge, and seems to work correctly.)

              – eyecatchUp
              Mar 18 at 11:42











              2














              Indeed, they don't support this variant, MDN articles should be updated.



              One way to polyfill this method is to run the scroll method in a requestAnimationFrame powered loop. Nothing too fancy here.



              The main problem that arises is how to detect when this variant is not supported. actually @nlawson's answer tackles this problem perfectly...



              For this, we can use the fact that a call to Window#scroll will fire a ScrollEvent if the viewPort actually did scroll.

              This means we can set up an asynchronous test that will:



              1. Attach an event handler to the ScrollEvent,

              2. Call a first time scroll(left , top) variant to be sure the Event will fire,

              3. Overwrite this call with a second one using the options variant.

              4. In the event handler, if we aren't at the correct scroll position, this means we need to attach our polyfill.

              So the caveat of this test is that it is an asynchronous test. But since you need to actually wait for the document has loaded before calling this method, I guess in 99% of cases it will be ok.



              Now to less burden the main doc, and since it is already an asynchronous test, we can even wrap this test inside an iframe, which gives us something like:



              /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
              (function ScrollPolyfill()

              // The asynchronous tester

              // wrapped in an iframe (will not work in SO's StackSnippet®)
              var iframe = document.createElement('iframe');
              iframe.onload = function()
              var win = iframe.contentWindow;
              // listen for a scroll event
              win.addEventListener('scroll', function handler(e)
              // when the scroll event fires, check that we did move
              if(win.pageXOffset < 99) // !== 0 should be enough, but better be safe
              attachPolyfill();

              // cleanup
              document.body.removeChild(iframe);
              );
              // set up our document so we can scroll
              var body = win.document.body;
              body.style.width = body.style.height = '1000px';

              win.scrollTo(10, 0); // force the event
              win.scrollTo(left:100, behavior:'instant'); // the one we actually test
              ;
              // prepare our frame
              iframe.src = "about:blank";
              iframe.setAttribute('width', 1);
              iframe.setAttribute('height', 1);
              iframe.setAttribute('style', 'position:absolute;z-index:-1');
              iframe.onerror = function()
              console.error('failed to load the frame, try in jsfiddle');
              ;
              document.body.appendChild(iframe);

              // The Polyfill

              function attachPolyfill()
              var original = window.scroll, // keep the original method around
              animating = false, // will keep our timer's id
              dx = 0,
              dy = 0,
              target = null;

              // override our methods
              window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;

              // going nowhere
              if(!dx && !dy)
              return;

              // save passed arguments
              target = opts;
              // save the rAF id
              animating = anim();

              ;
              // the animation loop
              function anim()

              )();




              Sorry for not providing a runable demo inside the answer directly, but StackSnippet®'s over-protected iframes don't allow us to access the content of an inner iframe on IE...
              So instead, here is a link to a jsfiddle.




              Post-scriptum:
              Now comes to my mind that it might actually be possible to check for support in a synchronous way by checking for the CSS scroll-behavior support, but I'm not sure it really covers all UAs in the history...




              Post-Post-scriptum:
              Using @nlawson's detection we can now have a working snippet ;-)






              /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
              (function ScrollPolyfill()

              // The synchronous tester from @nlawson's answer
              var supports = false
              test_el = document.createElement('div'),
              test_opts = top:0;
              // ES5 style for IE
              Object.defineProperty(test_opts, 'behavior',
              get: function()
              supports = true;

              );
              try
              test_el.scrollTo(test_opts);
              catch(e);

              if(!supports)
              attachPolyfill();


              function attachPolyfill()
              var original = window.scroll, // keep the original method around
              animating = false, // will keep our timer's id
              dx = 0,
              dy = 0,
              target = null;

              // override our methods
              window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;
              dy = (opts.top - window.pageYOffset) ;
              // the animation loop
              function anim()

              )();

              // OP's code,
              // by the time you click the button, the polyfill should already be set up if needed
              function scrollWin()
              window.scrollTo(
              left: 1000,
              top: 1000,
              behavior: 'smooth'
              );

              body 
              height: 5000px;
              width: 5000px;

              <p>Click the button to scroll the document window to 1000 pixels.</p>
              <button onclick="scrollWin()">Click me to scroll!</button>








              share|improve this answer

























              • Wow, this is an in depth answer for creating a polyfill from scratch. I checked it and it works well, but will stick with the simpler polyfill that avoids iframes linked from my own answer. Thanks for providing this though!

                – CDK
                Sep 14 '18 at 12:05






              • 1





                @CDK han.... of course someone already did it, bettter... Feel a bit stupid now to have wrote this in the first place without I saw your answer... Note that you can accept your own answer, which is not a bad one. And I see they used the idea I had in my Ps for detection, so it might be reliable enough after all...

                – Kaiido
                Sep 14 '18 at 12:26















              2














              Indeed, they don't support this variant, MDN articles should be updated.



              One way to polyfill this method is to run the scroll method in a requestAnimationFrame powered loop. Nothing too fancy here.



              The main problem that arises is how to detect when this variant is not supported. actually @nlawson's answer tackles this problem perfectly...



              For this, we can use the fact that a call to Window#scroll will fire a ScrollEvent if the viewPort actually did scroll.

              This means we can set up an asynchronous test that will:



              1. Attach an event handler to the ScrollEvent,

              2. Call a first time scroll(left , top) variant to be sure the Event will fire,

              3. Overwrite this call with a second one using the options variant.

              4. In the event handler, if we aren't at the correct scroll position, this means we need to attach our polyfill.

              So the caveat of this test is that it is an asynchronous test. But since you need to actually wait for the document has loaded before calling this method, I guess in 99% of cases it will be ok.



              Now to less burden the main doc, and since it is already an asynchronous test, we can even wrap this test inside an iframe, which gives us something like:



              /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
              (function ScrollPolyfill()

              // The asynchronous tester

              // wrapped in an iframe (will not work in SO's StackSnippet®)
              var iframe = document.createElement('iframe');
              iframe.onload = function()
              var win = iframe.contentWindow;
              // listen for a scroll event
              win.addEventListener('scroll', function handler(e)
              // when the scroll event fires, check that we did move
              if(win.pageXOffset < 99) // !== 0 should be enough, but better be safe
              attachPolyfill();

              // cleanup
              document.body.removeChild(iframe);
              );
              // set up our document so we can scroll
              var body = win.document.body;
              body.style.width = body.style.height = '1000px';

              win.scrollTo(10, 0); // force the event
              win.scrollTo(left:100, behavior:'instant'); // the one we actually test
              ;
              // prepare our frame
              iframe.src = "about:blank";
              iframe.setAttribute('width', 1);
              iframe.setAttribute('height', 1);
              iframe.setAttribute('style', 'position:absolute;z-index:-1');
              iframe.onerror = function()
              console.error('failed to load the frame, try in jsfiddle');
              ;
              document.body.appendChild(iframe);

              // The Polyfill

              function attachPolyfill()
              var original = window.scroll, // keep the original method around
              animating = false, // will keep our timer's id
              dx = 0,
              dy = 0,
              target = null;

              // override our methods
              window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;

              // going nowhere
              if(!dx && !dy)
              return;

              // save passed arguments
              target = opts;
              // save the rAF id
              animating = anim();

              ;
              // the animation loop
              function anim()

              )();




              Sorry for not providing a runable demo inside the answer directly, but StackSnippet®'s over-protected iframes don't allow us to access the content of an inner iframe on IE...
              So instead, here is a link to a jsfiddle.




              Post-scriptum:
              Now comes to my mind that it might actually be possible to check for support in a synchronous way by checking for the CSS scroll-behavior support, but I'm not sure it really covers all UAs in the history...




              Post-Post-scriptum:
              Using @nlawson's detection we can now have a working snippet ;-)






              /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
              (function ScrollPolyfill()

              // The synchronous tester from @nlawson's answer
              var supports = false
              test_el = document.createElement('div'),
              test_opts = top:0;
              // ES5 style for IE
              Object.defineProperty(test_opts, 'behavior',
              get: function()
              supports = true;

              );
              try
              test_el.scrollTo(test_opts);
              catch(e);

              if(!supports)
              attachPolyfill();


              function attachPolyfill()
              var original = window.scroll, // keep the original method around
              animating = false, // will keep our timer's id
              dx = 0,
              dy = 0,
              target = null;

              // override our methods
              window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;
              dy = (opts.top - window.pageYOffset) ;
              // the animation loop
              function anim()

              )();

              // OP's code,
              // by the time you click the button, the polyfill should already be set up if needed
              function scrollWin()
              window.scrollTo(
              left: 1000,
              top: 1000,
              behavior: 'smooth'
              );

              body 
              height: 5000px;
              width: 5000px;

              <p>Click the button to scroll the document window to 1000 pixels.</p>
              <button onclick="scrollWin()">Click me to scroll!</button>








              share|improve this answer

























              • Wow, this is an in depth answer for creating a polyfill from scratch. I checked it and it works well, but will stick with the simpler polyfill that avoids iframes linked from my own answer. Thanks for providing this though!

                – CDK
                Sep 14 '18 at 12:05






              • 1





                @CDK han.... of course someone already did it, bettter... Feel a bit stupid now to have wrote this in the first place without I saw your answer... Note that you can accept your own answer, which is not a bad one. And I see they used the idea I had in my Ps for detection, so it might be reliable enough after all...

                – Kaiido
                Sep 14 '18 at 12:26













              2












              2








              2







              Indeed, they don't support this variant, MDN articles should be updated.



              One way to polyfill this method is to run the scroll method in a requestAnimationFrame powered loop. Nothing too fancy here.



              The main problem that arises is how to detect when this variant is not supported. actually @nlawson's answer tackles this problem perfectly...



              For this, we can use the fact that a call to Window#scroll will fire a ScrollEvent if the viewPort actually did scroll.

              This means we can set up an asynchronous test that will:



              1. Attach an event handler to the ScrollEvent,

              2. Call a first time scroll(left , top) variant to be sure the Event will fire,

              3. Overwrite this call with a second one using the options variant.

              4. In the event handler, if we aren't at the correct scroll position, this means we need to attach our polyfill.

              So the caveat of this test is that it is an asynchronous test. But since you need to actually wait for the document has loaded before calling this method, I guess in 99% of cases it will be ok.



              Now to less burden the main doc, and since it is already an asynchronous test, we can even wrap this test inside an iframe, which gives us something like:



              /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
              (function ScrollPolyfill()

              // The asynchronous tester

              // wrapped in an iframe (will not work in SO's StackSnippet®)
              var iframe = document.createElement('iframe');
              iframe.onload = function()
              var win = iframe.contentWindow;
              // listen for a scroll event
              win.addEventListener('scroll', function handler(e)
              // when the scroll event fires, check that we did move
              if(win.pageXOffset < 99) // !== 0 should be enough, but better be safe
              attachPolyfill();

              // cleanup
              document.body.removeChild(iframe);
              );
              // set up our document so we can scroll
              var body = win.document.body;
              body.style.width = body.style.height = '1000px';

              win.scrollTo(10, 0); // force the event
              win.scrollTo(left:100, behavior:'instant'); // the one we actually test
              ;
              // prepare our frame
              iframe.src = "about:blank";
              iframe.setAttribute('width', 1);
              iframe.setAttribute('height', 1);
              iframe.setAttribute('style', 'position:absolute;z-index:-1');
              iframe.onerror = function()
              console.error('failed to load the frame, try in jsfiddle');
              ;
              document.body.appendChild(iframe);

              // The Polyfill

              function attachPolyfill()
              var original = window.scroll, // keep the original method around
              animating = false, // will keep our timer's id
              dx = 0,
              dy = 0,
              target = null;

              // override our methods
              window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;

              // going nowhere
              if(!dx && !dy)
              return;

              // save passed arguments
              target = opts;
              // save the rAF id
              animating = anim();

              ;
              // the animation loop
              function anim()

              )();




              Sorry for not providing a runable demo inside the answer directly, but StackSnippet®'s over-protected iframes don't allow us to access the content of an inner iframe on IE...
              So instead, here is a link to a jsfiddle.




              Post-scriptum:
              Now comes to my mind that it might actually be possible to check for support in a synchronous way by checking for the CSS scroll-behavior support, but I'm not sure it really covers all UAs in the history...




              Post-Post-scriptum:
              Using @nlawson's detection we can now have a working snippet ;-)






              /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
              (function ScrollPolyfill()

              // The synchronous tester from @nlawson's answer
              var supports = false
              test_el = document.createElement('div'),
              test_opts = top:0;
              // ES5 style for IE
              Object.defineProperty(test_opts, 'behavior',
              get: function()
              supports = true;

              );
              try
              test_el.scrollTo(test_opts);
              catch(e);

              if(!supports)
              attachPolyfill();


              function attachPolyfill()
              var original = window.scroll, // keep the original method around
              animating = false, // will keep our timer's id
              dx = 0,
              dy = 0,
              target = null;

              // override our methods
              window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;
              dy = (opts.top - window.pageYOffset) ;
              // the animation loop
              function anim()

              )();

              // OP's code,
              // by the time you click the button, the polyfill should already be set up if needed
              function scrollWin()
              window.scrollTo(
              left: 1000,
              top: 1000,
              behavior: 'smooth'
              );

              body 
              height: 5000px;
              width: 5000px;

              <p>Click the button to scroll the document window to 1000 pixels.</p>
              <button onclick="scrollWin()">Click me to scroll!</button>








              share|improve this answer















              Indeed, they don't support this variant, MDN articles should be updated.



              One way to polyfill this method is to run the scroll method in a requestAnimationFrame powered loop. Nothing too fancy here.



              The main problem that arises is how to detect when this variant is not supported. actually @nlawson's answer tackles this problem perfectly...



              For this, we can use the fact that a call to Window#scroll will fire a ScrollEvent if the viewPort actually did scroll.

              This means we can set up an asynchronous test that will:



              1. Attach an event handler to the ScrollEvent,

              2. Call a first time scroll(left , top) variant to be sure the Event will fire,

              3. Overwrite this call with a second one using the options variant.

              4. In the event handler, if we aren't at the correct scroll position, this means we need to attach our polyfill.

              So the caveat of this test is that it is an asynchronous test. But since you need to actually wait for the document has loaded before calling this method, I guess in 99% of cases it will be ok.



              Now to less burden the main doc, and since it is already an asynchronous test, we can even wrap this test inside an iframe, which gives us something like:



              /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
              (function ScrollPolyfill()

              // The asynchronous tester

              // wrapped in an iframe (will not work in SO's StackSnippet®)
              var iframe = document.createElement('iframe');
              iframe.onload = function()
              var win = iframe.contentWindow;
              // listen for a scroll event
              win.addEventListener('scroll', function handler(e)
              // when the scroll event fires, check that we did move
              if(win.pageXOffset < 99) // !== 0 should be enough, but better be safe
              attachPolyfill();

              // cleanup
              document.body.removeChild(iframe);
              );
              // set up our document so we can scroll
              var body = win.document.body;
              body.style.width = body.style.height = '1000px';

              win.scrollTo(10, 0); // force the event
              win.scrollTo(left:100, behavior:'instant'); // the one we actually test
              ;
              // prepare our frame
              iframe.src = "about:blank";
              iframe.setAttribute('width', 1);
              iframe.setAttribute('height', 1);
              iframe.setAttribute('style', 'position:absolute;z-index:-1');
              iframe.onerror = function()
              console.error('failed to load the frame, try in jsfiddle');
              ;
              document.body.appendChild(iframe);

              // The Polyfill

              function attachPolyfill()
              var original = window.scroll, // keep the original method around
              animating = false, // will keep our timer's id
              dx = 0,
              dy = 0,
              target = null;

              // override our methods
              window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;

              // going nowhere
              if(!dx && !dy)
              return;

              // save passed arguments
              target = opts;
              // save the rAF id
              animating = anim();

              ;
              // the animation loop
              function anim()

              )();




              Sorry for not providing a runable demo inside the answer directly, but StackSnippet®'s over-protected iframes don't allow us to access the content of an inner iframe on IE...
              So instead, here is a link to a jsfiddle.




              Post-scriptum:
              Now comes to my mind that it might actually be possible to check for support in a synchronous way by checking for the CSS scroll-behavior support, but I'm not sure it really covers all UAs in the history...




              Post-Post-scriptum:
              Using @nlawson's detection we can now have a working snippet ;-)






              /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
              (function ScrollPolyfill()

              // The synchronous tester from @nlawson's answer
              var supports = false
              test_el = document.createElement('div'),
              test_opts = top:0;
              // ES5 style for IE
              Object.defineProperty(test_opts, 'behavior',
              get: function()
              supports = true;

              );
              try
              test_el.scrollTo(test_opts);
              catch(e);

              if(!supports)
              attachPolyfill();


              function attachPolyfill()
              var original = window.scroll, // keep the original method around
              animating = false, // will keep our timer's id
              dx = 0,
              dy = 0,
              target = null;

              // override our methods
              window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;
              dy = (opts.top - window.pageYOffset) ;
              // the animation loop
              function anim()

              )();

              // OP's code,
              // by the time you click the button, the polyfill should already be set up if needed
              function scrollWin()
              window.scrollTo(
              left: 1000,
              top: 1000,
              behavior: 'smooth'
              );

              body 
              height: 5000px;
              width: 5000px;

              <p>Click the button to scroll the document window to 1000 pixels.</p>
              <button onclick="scrollWin()">Click me to scroll!</button>








              /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
              (function ScrollPolyfill()

              // The synchronous tester from @nlawson's answer
              var supports = false
              test_el = document.createElement('div'),
              test_opts = top:0;
              // ES5 style for IE
              Object.defineProperty(test_opts, 'behavior',
              get: function()
              supports = true;

              );
              try
              test_el.scrollTo(test_opts);
              catch(e);

              if(!supports)
              attachPolyfill();


              function attachPolyfill()
              var original = window.scroll, // keep the original method around
              animating = false, // will keep our timer's id
              dx = 0,
              dy = 0,
              target = null;

              // override our methods
              window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;
              dy = (opts.top - window.pageYOffset) ;
              // the animation loop
              function anim()

              )();

              // OP's code,
              // by the time you click the button, the polyfill should already be set up if needed
              function scrollWin()
              window.scrollTo(
              left: 1000,
              top: 1000,
              behavior: 'smooth'
              );

              body 
              height: 5000px;
              width: 5000px;

              <p>Click the button to scroll the document window to 1000 pixels.</p>
              <button onclick="scrollWin()">Click me to scroll!</button>





              /* Polyfills the Window#scroll(options) & Window#scrollTo(options) */
              (function ScrollPolyfill()

              // The synchronous tester from @nlawson's answer
              var supports = false
              test_el = document.createElement('div'),
              test_opts = top:0;
              // ES5 style for IE
              Object.defineProperty(test_opts, 'behavior',
              get: function()
              supports = true;

              );
              try
              test_el.scrollTo(test_opts);
              catch(e);

              if(!supports)
              attachPolyfill();


              function attachPolyfill()
              var original = window.scroll, // keep the original method around
              animating = false, // will keep our timer's id
              dx = 0,
              dy = 0,
              target = null;

              // override our methods
              window.scrollTo = window.scroll = function polyfilledScroll(user_opts) 0;
              dy = (opts.top - window.pageYOffset) ;
              // the animation loop
              function anim()

              )();

              // OP's code,
              // by the time you click the button, the polyfill should already be set up if needed
              function scrollWin()
              window.scrollTo(
              left: 1000,
              top: 1000,
              behavior: 'smooth'
              );

              body 
              height: 5000px;
              width: 5000px;

              <p>Click the button to scroll the document window to 1000 pixels.</p>
              <button onclick="scrollWin()">Click me to scroll!</button>






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jan 25 at 8:43

























              answered Sep 12 '18 at 6:30









              KaiidoKaiido

              45.3k467108




              45.3k467108












              • Wow, this is an in depth answer for creating a polyfill from scratch. I checked it and it works well, but will stick with the simpler polyfill that avoids iframes linked from my own answer. Thanks for providing this though!

                – CDK
                Sep 14 '18 at 12:05






              • 1





                @CDK han.... of course someone already did it, bettter... Feel a bit stupid now to have wrote this in the first place without I saw your answer... Note that you can accept your own answer, which is not a bad one. And I see they used the idea I had in my Ps for detection, so it might be reliable enough after all...

                – Kaiido
                Sep 14 '18 at 12:26

















              • Wow, this is an in depth answer for creating a polyfill from scratch. I checked it and it works well, but will stick with the simpler polyfill that avoids iframes linked from my own answer. Thanks for providing this though!

                – CDK
                Sep 14 '18 at 12:05






              • 1





                @CDK han.... of course someone already did it, bettter... Feel a bit stupid now to have wrote this in the first place without I saw your answer... Note that you can accept your own answer, which is not a bad one. And I see they used the idea I had in my Ps for detection, so it might be reliable enough after all...

                – Kaiido
                Sep 14 '18 at 12:26
















              Wow, this is an in depth answer for creating a polyfill from scratch. I checked it and it works well, but will stick with the simpler polyfill that avoids iframes linked from my own answer. Thanks for providing this though!

              – CDK
              Sep 14 '18 at 12:05





              Wow, this is an in depth answer for creating a polyfill from scratch. I checked it and it works well, but will stick with the simpler polyfill that avoids iframes linked from my own answer. Thanks for providing this though!

              – CDK
              Sep 14 '18 at 12:05




              1




              1





              @CDK han.... of course someone already did it, bettter... Feel a bit stupid now to have wrote this in the first place without I saw your answer... Note that you can accept your own answer, which is not a bad one. And I see they used the idea I had in my Ps for detection, so it might be reliable enough after all...

              – Kaiido
              Sep 14 '18 at 12:26





              @CDK han.... of course someone already did it, bettter... Feel a bit stupid now to have wrote this in the first place without I saw your answer... Note that you can accept your own answer, which is not a bad one. And I see they used the idea I had in my Ps for detection, so it might be reliable enough after all...

              – Kaiido
              Sep 14 '18 at 12:26











              2














              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






              share|improve this answer





























                2














                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






                share|improve this answer



























                  2












                  2








                  2







                  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






                  share|improve this answer















                  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







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 18 at 14:44

























                  answered Mar 18 at 12:32









                  eyecatchUpeyecatchUp

                  7,14823456




                  7,14823456





















                      0














                      Unfortunately, there is no way for that method to work in these two browsers.
                      You can check open issues here and see that they have done nothing on this issue.
                      https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/15534521/






                      share|improve this answer























                      • Already posted in a comment

                        – mplungjan
                        Sep 11 '18 at 12:56















                      0














                      Unfortunately, there is no way for that method to work in these two browsers.
                      You can check open issues here and see that they have done nothing on this issue.
                      https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/15534521/






                      share|improve this answer























                      • Already posted in a comment

                        – mplungjan
                        Sep 11 '18 at 12:56













                      0












                      0








                      0







                      Unfortunately, there is no way for that method to work in these two browsers.
                      You can check open issues here and see that they have done nothing on this issue.
                      https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/15534521/






                      share|improve this answer













                      Unfortunately, there is no way for that method to work in these two browsers.
                      You can check open issues here and see that they have done nothing on this issue.
                      https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/15534521/







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Sep 11 '18 at 12:55









                      Lazar NikolicLazar Nikolic

                      1,350519




                      1,350519












                      • Already posted in a comment

                        – mplungjan
                        Sep 11 '18 at 12:56

















                      • Already posted in a comment

                        – mplungjan
                        Sep 11 '18 at 12:56
















                      Already posted in a comment

                      – mplungjan
                      Sep 11 '18 at 12:56





                      Already posted in a comment

                      – mplungjan
                      Sep 11 '18 at 12:56











                      0














                      You can try to use Element.ScrollLeft and Element.ScrollTop property with Window.scrollTo().



                      Below is the example which is working with Edge and other browsers.






                      <html>
                      <style>
                      body
                      height: 5000px;
                      width: 5000px;

                      </style>
                      <p>Click the button to scroll the document window to 1000 pixels.</p>
                      <button onclick="scrollWin(this)">Click me to scroll!</button>
                      <script>
                      function scrollWin(pos)
                      window.scrollTo(pos.offsetTop+1000,pos.offsetLeft+1000);



                      </script>
                      </html>





                      Smooth behavior is not working with this code.



                      Reference:



                      Element.scrollLeft



                      Element.scrollTop



                      Regards



                      Deepak






                      share|improve this answer























                      • Thanks @deepak - but the main reason I wanted to use scrollTo with the options was for the smooth scroll affect. Appreciate your answer though.

                        – CDK
                        Sep 13 '18 at 15:13











                      • @ CDK, I again made a several tests with smooth behavior with Edge. But this behavior is not working. so at present, It looks like this behavior is not supported with Edge.

                        – Deepak-MSFT
                        Sep 14 '18 at 1:46















                      0














                      You can try to use Element.ScrollLeft and Element.ScrollTop property with Window.scrollTo().



                      Below is the example which is working with Edge and other browsers.






                      <html>
                      <style>
                      body
                      height: 5000px;
                      width: 5000px;

                      </style>
                      <p>Click the button to scroll the document window to 1000 pixels.</p>
                      <button onclick="scrollWin(this)">Click me to scroll!</button>
                      <script>
                      function scrollWin(pos)
                      window.scrollTo(pos.offsetTop+1000,pos.offsetLeft+1000);



                      </script>
                      </html>





                      Smooth behavior is not working with this code.



                      Reference:



                      Element.scrollLeft



                      Element.scrollTop



                      Regards



                      Deepak






                      share|improve this answer























                      • Thanks @deepak - but the main reason I wanted to use scrollTo with the options was for the smooth scroll affect. Appreciate your answer though.

                        – CDK
                        Sep 13 '18 at 15:13











                      • @ CDK, I again made a several tests with smooth behavior with Edge. But this behavior is not working. so at present, It looks like this behavior is not supported with Edge.

                        – Deepak-MSFT
                        Sep 14 '18 at 1:46













                      0












                      0








                      0







                      You can try to use Element.ScrollLeft and Element.ScrollTop property with Window.scrollTo().



                      Below is the example which is working with Edge and other browsers.






                      <html>
                      <style>
                      body
                      height: 5000px;
                      width: 5000px;

                      </style>
                      <p>Click the button to scroll the document window to 1000 pixels.</p>
                      <button onclick="scrollWin(this)">Click me to scroll!</button>
                      <script>
                      function scrollWin(pos)
                      window.scrollTo(pos.offsetTop+1000,pos.offsetLeft+1000);



                      </script>
                      </html>





                      Smooth behavior is not working with this code.



                      Reference:



                      Element.scrollLeft



                      Element.scrollTop



                      Regards



                      Deepak






                      share|improve this answer













                      You can try to use Element.ScrollLeft and Element.ScrollTop property with Window.scrollTo().



                      Below is the example which is working with Edge and other browsers.






                      <html>
                      <style>
                      body
                      height: 5000px;
                      width: 5000px;

                      </style>
                      <p>Click the button to scroll the document window to 1000 pixels.</p>
                      <button onclick="scrollWin(this)">Click me to scroll!</button>
                      <script>
                      function scrollWin(pos)
                      window.scrollTo(pos.offsetTop+1000,pos.offsetLeft+1000);



                      </script>
                      </html>





                      Smooth behavior is not working with this code.



                      Reference:



                      Element.scrollLeft



                      Element.scrollTop



                      Regards



                      Deepak






                      <html>
                      <style>
                      body
                      height: 5000px;
                      width: 5000px;

                      </style>
                      <p>Click the button to scroll the document window to 1000 pixels.</p>
                      <button onclick="scrollWin(this)">Click me to scroll!</button>
                      <script>
                      function scrollWin(pos)
                      window.scrollTo(pos.offsetTop+1000,pos.offsetLeft+1000);



                      </script>
                      </html>





                      <html>
                      <style>
                      body
                      height: 5000px;
                      width: 5000px;

                      </style>
                      <p>Click the button to scroll the document window to 1000 pixels.</p>
                      <button onclick="scrollWin(this)">Click me to scroll!</button>
                      <script>
                      function scrollWin(pos)
                      window.scrollTo(pos.offsetTop+1000,pos.offsetLeft+1000);



                      </script>
                      </html>






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Sep 12 '18 at 2:59









                      Deepak-MSFTDeepak-MSFT

                      1,144117




                      1,144117












                      • Thanks @deepak - but the main reason I wanted to use scrollTo with the options was for the smooth scroll affect. Appreciate your answer though.

                        – CDK
                        Sep 13 '18 at 15:13











                      • @ CDK, I again made a several tests with smooth behavior with Edge. But this behavior is not working. so at present, It looks like this behavior is not supported with Edge.

                        – Deepak-MSFT
                        Sep 14 '18 at 1:46

















                      • Thanks @deepak - but the main reason I wanted to use scrollTo with the options was for the smooth scroll affect. Appreciate your answer though.

                        – CDK
                        Sep 13 '18 at 15:13











                      • @ CDK, I again made a several tests with smooth behavior with Edge. But this behavior is not working. so at present, It looks like this behavior is not supported with Edge.

                        – Deepak-MSFT
                        Sep 14 '18 at 1:46
















                      Thanks @deepak - but the main reason I wanted to use scrollTo with the options was for the smooth scroll affect. Appreciate your answer though.

                      – CDK
                      Sep 13 '18 at 15:13





                      Thanks @deepak - but the main reason I wanted to use scrollTo with the options was for the smooth scroll affect. Appreciate your answer though.

                      – CDK
                      Sep 13 '18 at 15:13













                      @ CDK, I again made a several tests with smooth behavior with Edge. But this behavior is not working. so at present, It looks like this behavior is not supported with Edge.

                      – Deepak-MSFT
                      Sep 14 '18 at 1:46





                      @ CDK, I again made a several tests with smooth behavior with Edge. But this behavior is not working. so at present, It looks like this behavior is not supported with Edge.

                      – Deepak-MSFT
                      Sep 14 '18 at 1:46

















                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52276194%2fwindow-scrollto-with-options-not-working-on-microsoft-edge%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      1928 у кіно

                      Захаров Федір Захарович

                      Ель Греко