HomeiOS Developmentjavascript - `window.scrollTo` scrolls exterior the container on iOS Safari

javascript – `window.scrollTo` scrolls exterior the container on iOS Safari


I’m working into a difficulty with window.scrollTo on iOS Safari.

On desktop browsers (Chrome/Firefox/Edge), this works as anticipated:

window.scrollTo(0, doc.physique.scrollHeight);

Even when resizing the window, the scroll goes accurately to the underside of the web page.

However on iOS Safari, the conduct is totally different:

  • It scrolls previous the underside of my fundamental container (part#part).
  • The top of the
    will get aligned on the prime of the viewport.
  • I then have to manually scroll a bit bit up/down earlier than the browser “fixes” the scroll place (as if Safari realizes it scrolled exterior the legitimate vary).

Right here’s the simplified HTML/CSS:






[...]

Issues I’ve already tried:

  • window.scrollTo(0, doc.physique.scrollHeight);

  • Scrolling the part itself:

    part.scrollTo({
        prime: part.scrollHeight,
        conduct: 'easy',
    });
    
  • Wrapping the scroll in a setTimeout (50ms delay).

Sadly, none of those repair the difficulty on iOS Safari.

Has anybody encountered this conduct earlier than, or is aware of a dependable workaround to ensure the scroll goes accurately to the underside on cellular Safari?

Thanks!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments