Loading video...

Video Failed to Load

Go Home

the little details™ Use trigonometric functions in CSS to create a smooth staggered transition delay 🎬 .character { transition-delay: calc(sin((var(--index) / 12) * 45deg) * 0.475s); }

539,632 views • 2 years ago •via X (Twitter)

10 Comments

jhey ▲🐻🎈's profile picture
jhey ▲🐻🎈2 years ago

Here's the @CodePen link if you want to check it out! 🤙 Thrown together in some React for convenience 🤓 Should extract into a <CodeReveal/> component 💯🧱

Charlotte 🦄🧚‍♀️'s profile picture
Charlotte 🦄🧚‍♀️2 years ago

I'm going to just secretly put this into the app I'm working on and see if they notice 😄

jhey ▲🐻🎈's profile picture
jhey ▲🐻🎈2 years ago

Put it in the footer, no one looks there 👀😅

Gabe's profile picture
Gabe2 years ago

Yeah, how do you get the —index variable? Thats the true magic here i cannot fanthom… cuz normally that would all be part of a javascript loop

jhey ▲🐻🎈's profile picture
jhey ▲🐻🎈2 years ago

Style it inline on the HTML <span class="digit" style="--index: 0;">1</span> <span class="digit" style="--index: 1;">9</span>

Charles Anim's profile picture
Charles Anim2 years ago

Show us the code

We Buy Once's profile picture
We Buy Once2 years ago

Amazing stuff!

Roxana Muntian's profile picture
Roxana Muntian2 years ago

Those animations are so cool! At some point, it almost felt like the eye blinked. 😊 I might add this animation to the app that I am working on. It's the next level for CSS!

SM Irving's profile picture
SM Irving2 years ago

Very smooth! I wrote something similar in Sass as a function that lets you call a bunch of different CSS custom timing-functions from different keywords, Penner equations and Trig stuff. This makes me want to modify or write a separate function that returns calc equations instead

Fonzy's profile picture
Fonzy2 years ago

goated animations

Related Videos

CSS Tip! 🎠 You can create a responsive infinite marquee animation with container queries and no duplicate items 🤙 li{ animation: slide; } @​keyframes slide { to { translate: 0% calc(var(--i) * -100%);}} The trick is animating the items, not the list 😎 More tricks 👇 To get this one working, you need to animate the items and not the list (Watch the video first?). Each item needs to know its row index (--i) in the list and the parent needs to know how many rows are in the list: ul { --count: 12; } li:nth-of-type(1), li:nth-of-type(2) { --i: 0; } li:nth-of-type(3), li:nth-of-type(4) { --i: 1; } Once you have that, translate each item based on its row index in the list li { translate: 0% calc((var(--count) - var(--i)) * 100%); } Now for the animation. The key here is that each row has an animation-delay calculated from its index (--i). That number is offset to make it negative so the animation start is offset ✨ ul { --duration: 10s; } li { --delay: calc((var(--duration) / var(--count)) * (var(--i) - 8)); animation: slide var(--duration) var(--delay) infinite linear; } Make sure to wrap that animation in: @​media (prefers-reduced-motion: no-preference) { ... } Lastly, the fun parts! 🤓 To create the "vignette" mask. Use a layered mask on the container 😷 .scene { --buff: 3rem; height: 100%; width: 100%; mask: linear-gradient(transparent, white var(--buff) calc(100% - var(--buff)), transparent), linear-gradient(90deg, transparent, white var(--buff) calc(100% - var(--buff)), transparent); mask-composite: intersect; } To create the 3D skewed effect, use a chained transform (Try toggling it in the demo ⚡️): .grid { transform: rotateX(20deg) rotateZ(-20deg) skewX(20deg); } As for the responsive part, use container queries! 🔥 article { container-type: inline-size; } When the article (card) is narrower than 400px update the grid and animation settings 🤙 Double the rows means double the duration! @​container (width < 400px) { .grid { --count: 12; grid-template-columns: 1fr; } li:nth-of-type(1) { --i: 0; } li:nth-of-type(2) { --i: 1; } li:nth-of-type(3) { --i: 2; } li:nth-of-type(4) { --i: 3; } li { --duration: 20s; } } CSS has the magic to be able to update those animations at runtime based on your custom property values 😎 An added bonus in this demo is that it doesn't require any JavaScript at all, for any of it 🤯 We can use CSS :has() for those toggles that update the styles, even the theme toggle! 🫶 Any questions, let me know! Make sure to check out the video. Will do a walkthrough one to follow-up 🤙 CodePen.IO link below! 👇

jhey ʕ•ᴥ•ʔ

541,845 views • 2 years ago