madebysource / animated-scrollto

Animated scrolling without any dependency on libraries
MIT License
319 stars 57 forks source link

document.body no longer seems to work on Chrome & firefox. #19

Open moehammoud opened 7 years ago

moehammoud commented 7 years ago

So it seems that using the element document.body no longer works on Chrome and Firefox. It still works just fine on Safari and IE. The fix for Chrome seems to be using document.documentElement instead of document.body. The issue now is that the fix no longer works in Safari. I can include a simple if else statement to ensure each browser has a valid animatedScrollTo function called, but I wonder if there is a more elegant solution that could be used or included in the animatedScrollTo library.

Example of my animateScrollTo call after syntax change.

animatedScrollTo(
      document.documentElement,
      el.offsetTop,
      500,
      function(){console.log("animateScroll fired")}
    );
alexjfno1 commented 7 years ago

+1 I have the same issue.

danilostrazzullo commented 7 years ago

Probably the "future-proof" fix could be using document.scrollingElement. Currently it works fine in every modern desktop browser (but it's NOT supported in IE <= 11). For more details take a look to the related browser compatibility table on MDN.