I'm trying to make a page transition with vue router in Vue 3
This image sums up what I'm trying to do
I'm building a website with different pages (on the image: blue zone) that all have a scroll and a common fixed navigation bar at the top. If you click on one of the links of the topbar, it should move the entire page container to the bottom by 100vh to reveal a special view (on the image: red zone)
My problem
As the yellow bar is fixed, I don't manage to make it leave with the blue page, it stays fixed at y:0
I want to avoid clumsy stuff such as quickly adding on beforeRouteLeave a position:absolute top the navigation bar and compensating the top position based on scroll position.
I don't really manage to make the 2 views be on top of each other, so that the blue page reveals the red page that is already in the right position.
I don't manage to wrap my head around how I should approach this
I've been trying different things for a few days:
Single <router-view> in App.vue that contains the blue views, and the red view. No luck.
Two different <router-view> in App.vue. No luck.
Various levels of wrapper with absolute, overflow hidden, given 100vh values, etc... No luck
My questions
Would you know how I should split the different parts? (app, wrappers, sub-wrappers, croppers, ..)
Can it be done with a single <router-view>?
Can it be done without super clumsy JS on route change?
Thank you for reading
I hope this idea can help you.
Since page is just a component that changed on redirect, you can create a page that contains both of your pages. For example, according to your pictures, I'll have 2 pages (
Red
andBlue
). Then, I'll createMerge
that containsRed
andBlue
This is
Red.vue
This is
Blue.vue
This is
Merge.vue
Put both
Red
andBlue
insideMerge
. Then wrapBlue
with<Transition/>
. By this, you can add transition toBlue
and make it slide down to revealRed
. Finally, insideRed
andBlue
, emit some signal when you try to redirectThe detail is here: https://stackblitz.com/edit/vue-fyebnk
In this example, I've made
Blue
slides down when go toRed
and slides up when go back fromRed
toBlue
.In
Blue
, you can seeRed
is rendered when you look atBlue
right side. But it up to you to modify it since loadingRed
first can be wasting if user is not gonna use it.And of course, the transition can only occur if you click link inside
Blue
orRed
. Any other redirect method will just immediately showBlue
orRed
Beside, if library is a way to go. I think you should have a look at RevealJS or sli.dev
Good luck to you