jrh Posted March 30, 2023 Share Posted March 30, 2023 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 More sharing options...
elegantseagulls Posted March 30, 2023 Share Posted March 30, 2023 I think that's just browser behavior for when you remove content in Safari... I'd suggest also manually setting your scroll position immediate after you remove the content. 1 Link to comment Share on other sites More sharing options...
Solution GreenSock Posted March 30, 2023 Solution Share Posted March 30, 2023 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; } 1 Link to comment Share on other sites More sharing options...
jrh Posted March 31, 2023 Author Share Posted March 31, 2023 Amazing! Thank you @GreenSock, that seems to work well.. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now