I have found that when using page transitions, the page will snap to the top before transitioning out then the new page will transition in. I do want the new page to start at the top however perhaps the code that scrolls the current page to top before transitioning needs to happen a little later.
Here's a codesandbox: https://codesandbox.io/s/qkpy6nxxnj
To replicate the issue, click "Blog" then scroll down a ways then click a link and you'll see it snap to top, then transition out then the new page transition in
Hello, I have the same issue. @matt3224 did you find any workaround maybe?
@nick-pripakis yes kinda, you can do it by delaying the incoming page transition in by the duration of the out transition
The unfortunate part of page transitions in their current state is lack of control. For example i'd like to click a link, have the page smooth scroll to the top, fade out and then fade in the new page. As far as I'm aware we can't stop it jumping to the top first.
Another example where control over this stuff would be handy is sliding a new page in from the right say, where you wouldn't want the existing page to go to the top at all
I'm sure we'll see these added at some point but i don't think enough of us run into it for it to be high priority unfortunately 馃様
Thank you, I'm gonna try it out when I have the time. No page transitions for now. Yes, I hope such a functionality would be implemented at some point, because page transitions are basically broken right now in their current state, for me at least. 馃槙 In Vue for example, there is a scrollBehavior function which can be implemented on each route, and you have do pretty much whatever you want with the scrolling.
This can be solved by using custom CSS transitions. This is the transition function I use which takes into account the window's scroll distance:
function fade(node, { delay = 0, duration = 400, offset=window.scrollY }) {
const o = +getComputedStyle(node).opacity;
return {
delay,
duration,
offset,
css: t => `opacity: ${t * o}; margin-top: -${offset}px`
};
}
Thank you @rosslh, this works great.
Still, working with page transitions feels not really straightforward. Another option would probably be to add the undocumented sapper-noscroll #737 attribute to navigation links and scroll to the top between the pages using transition events.
Upon further testing鈥β爐here unfortunately is still weird scroll jumping going on.
I think this is fixed now. https://github.com/sveltejs/sapper/pull/1320
Most helpful comment
This can be solved by using custom CSS transitions. This is the transition function I use which takes into account the window's scroll distance: