Jump to content
Search Community

scrollTo and remove() element.

jrh test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Hey all,


So I'm trying to figure out why this approach won't work in Safari.

 

The CodePen link includes a really trimmed down version of a larger piece of functionality I'm building where content is fetched dynamically, placed in an element and scrolled to. After that, the previous content above is removed from the DOM. All this takes place in an 'overlay' element that is fixed in place and has overflow auto applied.

 

This seems to work fine in all browsers, except for Safari. Where after the scroll animation and original content being removed, the scroll position goes all wonky.

 

Just wondering if this is a known issue, if there are any fixes or if there might be a better approach altogether?

 

Cheers.

J

See the Pen qBMGXVV by j-rh (@j-rh) on CodePen

Link to comment
Share on other sites

  • Solution

Yep, you're shifting the whole layout around, so the browser has to figure out where to place the new scroll position and my guess is different browsers handle that differently. Perhaps just do something like: 

 onComplete: () => {
   let bounds = newContent.getBoundingClientRect();
   currentContent.remove();
   fetchContainer.scrollTop += newContent.getBoundingClientRect().top - bounds.top;
 }

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...