Replies: 3 comments
-
|
Hi @fweth 👋🏼, you can set the scroll position to what ever you like in a listener to the This even works with the default swap function independent of custom swaps. This technique can be used to completely avoid changes in the scroll position during navigation. If you want, you can wait for the view transition to finish before you scroll somewhere else: |
Beta Was this translation helpful? Give feedback.
-
|
@martrapp awesome, thanks a lot! This definitely works, but are you happy with the underlying API? It feels to me like your solution is working a bit around the API, saving the scroll position, then let Astro reset it, and then restore it manually afterwards? In my case with the exit animation, it would mean saving the scroll position, let Astro reset it, restore it, and after the visual swap, reset it again, wouldn't it be nicer if the API exposed the scroll position handling just like it exposes focus restoration, so we could call it whenever we need it? Anyway, feel free to close the RFC if you like! |
Beta Was this translation helpful? Give feedback.
-
|
Haha, good point. If we were to reinvent the client router today, it would probably look different ;-) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Summary
A scroll restoration function similar to focus restoration, which can be called in custom swap functions but can alse be left out if someone wants to bring their own logic.
Background & Motivation
Look at this example: https://stackblitz.com/edit/withastro-astro-queig9xm?file=src%2Flayouts%2FLayout.astro
Here I don't use view transitions but normal CSS transitions, which are sometimes mightier and have better cross browser support. When you scroll down the page before clicking a link, you see that Astro immediately scrolls to top, but I'd rather have this happening inside the timeout (or another delay mechanism).
It comes from this line: https://github.com/withastro/astro/blob/1e5b72c8df709b8ab966ed1d0f74977758bbf445/packages/astro/src/transitions/router.ts#L214
Goals
swapFunctions.saveScroll().Example
Beta Was this translation helpful? Give feedback.
All reactions