Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with Safari CSS Scroll Snap #157

Open
riccardolardi opened this issue Jul 22, 2020 · 3 comments
Open

Doesn't work with Safari CSS Scroll Snap #157

riccardolardi opened this issue Jul 22, 2020 · 3 comments

Comments

@riccardolardi
Copy link

riccardolardi commented Jul 22, 2020

Breaks in latest Safari if html or body element is set to scroll-snap-type: y mandatory;

@riccardolardi riccardolardi changed the title Doesn't work with CSS Scroll Snap Doesn't work with Safari CSS Scroll Snap Jul 22, 2020
@minseolee
Copy link

minseolee commented Jun 22, 2021

I did not set html or body element scroll-snap-type
And scroll snap does not work properly only at 'mobile safari'
iOS: 14.4.1 / React.js
Did anyone solved this problem?

@MarkVasile
Copy link

Strange hack, but it works: disabling the scroll-snap before scrolling, then re-enabling and also calling scrollIntoView().
Note: I am scrolling a few slides, which are <li> items here, please adjust according to your needs.
Note: I am using two polyfills: 'css-scroll-snap-polyfill' and 'smoothscroll-polyfill'.

Also, I don't know why it's necessary to set scrollSnapType on both 'body' and 'html' (I only have it on in the css file), but I couldn't get it to work with only one setting.

      const prop = {
        behavior: 'smooth',
        block: 'start',
        top: slides[index].offsetTop,
      }
      document.body.style.scrollSnapType = 'none'
      document.getElementsByTagName('html')[0].style.scrollSnapType = 'none'
      window.scrollTo(prop)
      setTimeout(() => {
        document.body.style.scrollSnapType = 'y mandatory'
        document.getElementsByTagName('html')[0].style.scrollSnapType = 'y mandatory'
        document.getElementsByTagName('li')[index].scrollIntoView()
      }, 500)

@artturipi
Copy link

On Mac, Safari version 14.0.3. smoothscroll works fine with scroll snap at least for element. I'm not sure which version @riccardolardi is talking about as latest, but I'd assume it's version 13.x.x. However, I still had this issue with iOS Safari version 15.3.1. After updating to 15.4.1. today, the issue disappeared.

I tried to apply @MarkVasile workaround because of this issue on iOS. However it did not work for me for safari 14.0.3. The symptom was that after timeout, the scroll would snap to the beginning of the container element, which obviously is bad. I tried some fixes like disabling scroll by setting overflow: hidden or setting the scroll position again after adjusting scrollSnapType to mandatory but that was glitchy and unreliable. Moral of the story: if you've used this workaround, it might be a good idea to either stop using it or checking for Safari version numbers and only applying it to some range of versions. I'm not sure how you'd go about figuring out the exact version range to apply the fix, though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants