Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

Probably old news now, but the CSS View Transition API is SUPER cool! Entry/exit layout animations like this used to be super complicated or require giant libraries. Now it's like 2 lines of JS, and a few lines of CSS if you want to customize the animation. Amazing! 🤯

98,021 Aufrufe • vor 2 Jahren •via X (Twitter)

10 Kommentare

Profilbild von Devon Govett
Devon Govettvor 2 Jahren

Code:

Profilbild von Kushagra Gour @css_battle
Kushagra Gour @css_battlevor 2 Jahren

yes! And here's a demo without the performance hit of using flushSync

Profilbild von Devon Govett
Devon Govettvor 2 Jahren

flushSync is fine. This is the exact type of thing it is designed for. Actually in this case it may even be faster. When startViewTransition is called it freezes the DOM to take a snapshot. Flushing synchronously reduces the time the page is frozen because updates occur immediately rather than waiting unnecessarily.

Profilbild von Jim Meyer
Jim Meyervor 2 Jahren

Super clean. I immediately tried clicking the add button before the current transition had finished, finding that it then ignores that click. Limitation of freezing the DOM, or is there a way to stack the transitions?

Profilbild von Devon Govett
Devon Govettvor 2 Jahren

Yeah it’s a limitation of the current API but I think the spec authors are aware of it so hopefully it’ll get better eventually

Profilbild von Mostafa
Mostafavor 2 Jahren

Is using the "flushSync" recommended for lists?

Profilbild von Devon Govett
Devon Govettvor 2 Jahren

In this case it’s required for the view transition to take effect. The DOM updates have to occur inside that callback

Profilbild von Ismal Zikri
Ismal Zikrivor 2 Jahren

can you drop that link pls? pretty excited to try it ...

Profilbild von Devon Govett
Devon Govettvor 2 Jahren

No problem

Profilbild von Nate Smith
Nate Smithvor 2 Jahren

Very very cool!

Ähnliche Videos

CSS Trick 🍏 You can create that Apple-style blowout text effect with CSS scroll animations and fixed positioning ⚡️ .word { animation: blowout; animation-timeline: --section; } @​keyframes blowout { 0%, 95% { background: transparent; } to { transform: translateZ(99vh); background: #000; } } The trick here is to fix the position of some things in your layout and then animate them based on their non-fixed containers ⭐️ The .word is position: fixed within a that has a height of 200vh section { view-timeline: --section; } section:first-of-type { height: 200vh; } Every section has a view-timeline: --section that creates a scoped ViewTimeline for each section's children 🤙 As that first section scrolls out of view, you increase its opacity and move it on the z-axis towards you. That gives it the impression of scaling up 🆙 .word { animation: blowout, fade-in; animation-timing-function: ease-in; animation-fill-mode: both; animation-timeline: --section; animation-range: exit-crossing 10% exit 0%; } You can use the exit-crossing range combined with the exit range to get a timing you like ✨ Definitely experiment with these ranges to see how they play. The timing function creates interesting effects too! At the same time as the text scales up, you need to fade in the video and the text that goes with it. Again, you can use the parent container's ViewTimeline --section p, video { animation: fade-in, fade-out; animation-timing-function: ease-in; animation-fill-mode: both; animation-timeline: --section; } p { animation-range: entry 10% entry 35%, exit 0% exit 25%; } video { animation-range: entry 0% entry 25%, exit 10% exit 35%; } The timings are slightly different here. Again, you can play with them to get something that feels right for you! @​keyframes fade-in { to { opacity: 1; }} @​keyframes fade-out { to { opacity: 0; }} Theoretically, you should be able to do something with animation-direction: reverse/alternate like yesterday's demo video { animation: fade 2 both linear alternate-reverse; } The trick with this effect is all about timing and creating containers that are bigger than the content and using them to drive the animations 🏎️ The scroll-driven signature is a bonus! ✍️ Perhaps a follow-up on that one 🤙 As always, any questions, requests, etc. Hit me up! With this demo, the GreenSock ScrollTrigger code is included where the CSS scroll-driven animations API is not supported 🙌 That means you could use this demo today! CodePen.IO link below! 👇

jhey ʕ•ᴥ•ʔ

270,144 Aufrufe • vor 2 Jahren