Simple, Amazing Page Transitions
This website has one of the coolest page transitions I've ever seen. So obviously upon looking into it, I needed to do a quick write-up on how to do it so I can reproduce in the future.
It's very simple in a way that is impressive.
Firstly, just add:
1 | |
2 | |
3 | |
This will set up view transitions between pages. I believe if nothing is specified, the default will be a cute little cross-fade.
Next, to customize how the transition happens you need to start with the following:
1 | |
2 | |
3 | |
This gives a name to whatever you are transitioning (in this case, root) and says what element to transition (which here is :root or everything). You can make the view-transition-name anything you want.
Then you specify how it'll change with the ::view-transition-old(root) {...} and ::view-transition-new(root) {...} properties.
From here we can specify something like:
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
This is how Heydon Pickering does it in their website and it makes this distortion effect that was so cool it stopped me in my tracks and caused me to rabbit hole away my vacation morning to look into how they did it.
Here's what the distort-in animation looks like:
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
distort-out looks about the same.
These filters are deceptively simple. It applies opacity and some filtering. But what is the url(...) bit refer to? Just a little svg magic!
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
Throw that somewhere in your html markup and define each filter in the defs (short for definition) section. The id is what will connect to the url(#id) in the keyframes. There are lots of filter primitives which you can mix and match to create incredible effects. In the above example, Heydon is using feTurbulence to create Perlin noise and connecting it to the page with the feDisplacementMap.
To fill out the above example, you'll just make a couple more distort filters, varying the baseFrequency and you have yourself a most amazing (and pretty punk) page transition.