As the title says, it works perfectly fine on Chrome. But in Safari, it just sets the page to the desired top and and left position. Is this the expected behaviour? Is there a way to make it work nicely?
With the new version of Safari 15.4, the CSS property scroll-behavior: smooth will block the JS scroll on element. scrollTop = xx . The release note says scroll-behavior props will be supported by this new version, but it only blocks scrolls...
Using jquery there is a equivalent for scroll-behavior: smooth. Try this: $('html, body'). animate({ scrollTop: 0 }, 1500);
The scroll-behavior property specifies whether to smoothly animate the scroll position, instead of a straight jump, when the user clicks on a link within a scrollable box. Default value: auto.
Use smootscroll polyfill (solution for all browsers), easy applicable and lightweight dependency: https://github.com/iamdustan/smoothscroll
Once you install it via npm or yarn, add it to your main .js, .ts file (one which executes first)
import smoothscroll from 'smoothscroll-polyfill'; // or if linting/typescript complains import * as smoothscroll from 'smoothscroll-polyfill'; // kick off the polyfill! smoothscroll.polyfill();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With