Loading video...

Video Failed to Load

Go Home

Future CSS Tip! ๐Ÿ”ฎ You can create sweet scroll-driven micro-interactions using CSS scroll-driven animations ๐Ÿ˜Ž .avatar { animation: scale-down; animation-timeline: scroll(); animation-range: var(--header-range); } @ keyframes scale-down { to { scale: 0.3; } } What's happening in this one? ๐Ÿ‘€ 1. Avatar moves and scales down as the header...

685,804 views โ€ข 3 years ago โ€ขvia X (Twitter)

10 Comments

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ3 years ago

Here's that @CodePen link! ๐Ÿš€ Hop into Chrome 115+ and take it for a spin ๐Ÿค™

Taeho's profile picture
Taeho3 years ago

Did you come up with this? This is mind blowing since Iโ€™m just getting used to parent child relationships. Def gonna try this out!

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ3 years ago

Yeah, it's a combination of a couple of demos I built last year for speaking at conferences โœจ Fun part was filming myself for the image ๐Ÿ˜…

Alex Hall's profile picture
Alex Hall3 years ago

This looks so cool! I've got a slight issue on Chrome Android where the background image is halfway across the page. Definitely going to be having a play with this!

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ3 years ago

Ahh โ€“ Thanks for pointing this out Alex ๐Ÿ™ I think I've fixed it ๐Ÿคž Needed to set some max-widths, etc. Glad you like it!

Rob DiMarzo's profile picture
Rob DiMarzo3 years ago

I'm out here lookin at your css like

Jesse Schoberg's profile picture
Jesse Schoberg3 years ago

Well done ๐Ÿซก

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ3 years ago

Thanks Jesse ๐Ÿ™

Art San Diego's profile picture
Art San Diego3 years ago

Nooice ๐Ÿ”ฅ

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ3 years ago

@artsnux ๐Ÿ™๐Ÿ™

Related Videos

CSS Tip! ๐Ÿณ You can add little details like this scale down on scroll effect with scroll-driven animations and some sticky positioning ๐Ÿค™ section { animation: scale-down; animation-timeline: view(); animation-range: exit; } @โ€‹keyframes scale-down { to { scale 0.8; } ] In this smaller example, you can lean into using the position to drive an animation that scales itself down as it leaves the viewport (Seen on the Apple Vision Pro site ๐Ÿ) The nice thing here is that if you don't have scroll-driven animations, the user still gets a good experience โœจ So how do you do it? There isn't much to it header { transform-origin: 50% 0%; animation: scale-down both ease-in; animation-timeline: view(); animation-range: exit; view-timeline: --header; } @โ€‹keyframes scale-down { to { scale: 0.8 0.8; } } That's it. The layout makes use of position: sticky so that the element stays in the shot whilst you scroll the page. As it leaves the page, it scales down inside the ๐Ÿซถ The other smol animation here is fading the overlay on the video out ๐Ÿ˜Ž Real easy. You may notice the view-timeline you defined above for the ๐Ÿ‘€ header { view-timeline: --header; } You have a pseudoelement on the text content of the header that lives inside a header > section::before { background: hsl(0 0% 0% / 0.75); opacity: 1; animation: fade both linear; animation-timeline: --header; animation-range: exit-crossing 0% exit 0%; } @โ€‹keyframes fade { to { opacity: 0; } } You use a slightly smaller range on this with exit-crossing to fade it out before you start the scale down animation ๐Ÿค That's it! Thought this smaller example would be easier to grok for people ๐Ÿ™ It's also covered with JavaScript if you really want it for your sites ๐Ÿค™ CodePen.IO link below ๐Ÿ‘‡

jhey ส•โ€ขแดฅโ€ขส”

146,270 views โ€ข 2 years ago

CSS Tip! ๐Ÿ“œ You can use scroll-driven animations to progressively enhance collapsing a floating call to action ๐Ÿค .cta { animation: shrink; animation-timeline: scroll(); animation-range: 0 100px; } @โ€‹keyframes shrink { to { width: 48px; } } That's the gist of it. Use the body scroll position with animation-timeline: scroll(). Define the animation-range as when you have scrolled 100px. There's a little more though ๐Ÿค“ That would "scrub" the width animation. Ideally, you want to trigger that animation. You could animate a custom property with steps() timing and use that to define the width โœจ @โ€‹property --scrub { syntax: ' '; inherits: true; initial-value: 0; } body { animation: scrub both steps(1, end); animation-timeline: scroll(); animation-range: 0 100px; } Then transition the --scrub property on the CTA and use it for the width ๐Ÿค™ .cta { transition: --scrub 0.2s; width: calc(48px + (120px * (1 - (var(--scrub) / 100)))); } Other animations are a matter of preference and timing. For example, you could then make the hand wave, scale down the size, and then slide a gradient across ๐Ÿ˜‰ They have the same structure and technique as the original concept. Waving the hand? ๐Ÿ‘‹ Run it twice, offset the transform-origin. .hand { animation: wave both linear 2; animation-timeline: scroll(); animation-range: 30vh 50vh; transform-origin: 65% 75%; } @โ€‹keyframes wave { 50% { rotate: 20deg; } } How's it progressively enhanced? Wrap everything in a @โ€‹supports query and a @โ€‹media query. If there isn't support, users still get a good experience. It's a floating action button that's circular and already collapsed ๐Ÿค™ @โ€‹supports(animation-timeline: scroll()) { @โ€‹media(prefers-reduced-motion: no-preference) {...} } Definitely have a play with the code. Amazing what we're going to be able to do with CSS alone! ๐Ÿ”ฅ CodePen.IO link below! ๐Ÿ‘‡

jhey ส•โ€ขแดฅโ€ขส”

177,985 views โ€ข 2 years ago

CSS Tip! ๐Ÿšฅ You can create these trending expanding scroll indicators with scroll-driven animations and flex ๐Ÿค™ .indicator { animation: grow; animation-range: contain calc(50% - var(--size)...; animation-timeline: var(--card); } @โ€‹keyframes grow { 50% { flex: 3; }} What's the trick? Put the indicators in a container using flex layout and set a width larger than the number of indicators ๐Ÿ˜‰ .indicators { aspect-ratio: 7 / 1; display: flex; } Importantly, set no gap ๐Ÿค To mimic the gap set a transparent border on each indicator and set the background using padding-box .indicator { background: linear-gradient(#โ€‹fff, #โ€‹fff) padding-box; border-radius: 50px; border: 4px solid transparent; } Now for the animation. You want to create a view-timeline for each card that moves across ๐Ÿค™ li:nth-of-type(1) { view-timeline: --one inline; } li:nth-of-type(2) { view-timeline: --two inline; } Make sure they use the inline axis too! The trick is hoisting these view-timeline so the indicators can use them with timeline-scope ๐Ÿ‘€ .track { timeline-scope: --one, --two, ...; } All that's left is for you to create the animation piece using some calc with the card size โšก๏ธ .indicator { --size: calc(var(--card-width) * 0.9); animation: grow both linear; animation-range: contain calc(50% - var(--size)) contain calc(50% + var(--size)); } .indicator:nth-of-type(1) { animation-timeline: --one; } .indicator:nth-of-type(2) { animation-timeline: --two; } @โ€‹keyframes grow { 50% { flex: 3; }} And there you have it, responsive scroll indicators using CSS scroll-driven animations ๐Ÿ˜Ž Sprinkle a little JavaScript to make them clickable and scroll the the right card โœจ const shift = (event) => { if (eventโ€‹.target.tagName === "BUTTON") { const index = [...event.target.parentNode.children].indexOf(eventโ€‹.target); const item = document.querySelector(`li:nth-of-type(${index + 1})`); item.scrollIntoView({ behavior: "smooth", inline: "center" }); } }; As always, any questions or suggestions, let me know. I've put a JavaScript fallback in to use GSAP in browsers that don't have scroll-driven animations ๐Ÿซถ CodePen.IO link below! ๐Ÿ‘‡

jhey ส•โ€ขแดฅโ€ขส”

575,728 views โ€ข 2 years ago

Future CSS Tip! ๐Ÿ You can create this Apple-style photo scroller by combining CSS scroll-driven animations and CSS scroll-snap ๐Ÿ˜ Peep those changing captions ๐Ÿ‘€ No JS! img { animation: highlight both linear; animation-timeline: view(inline); ๐Ÿ‘ˆ Horizontal animation-range: cover 0% cover 50%; ๐Ÿ‘ˆ Finish } @ keyframes highlight { 50% { translate: 0 0; scale: var(--starting-scale); ๐Ÿ‘ˆ props opacity: var(--starting-opacity); ๐Ÿ‘ˆ } 100% { translate: 0 0; scale: 1; opacity: 1; } } Without the animation support, you get a standard unordered list containing some s ๐Ÿค™ How do we swap the captions though? The "trick" is to use position: absolute on the figcaption and animate their opacity based on the ViewTimeline of their parent list item ๐Ÿ˜Ž figcaption { animation: show both linear; animation-timeline: --list-item; } @ keyframes show { 0%, 45%, 55%, 100% { opacity: 0; } 50% { opacity: 1; } } li { view-timeline-name: --list-item; view-timeline-axis: inline; ๐Ÿ‘ˆ important! } The parent of the scroll track uses position: relative so all the captions sit in the middle even though they are in the right place for the markup ๐Ÿ™Œ The last bit is the scroll-snap ๐Ÿค™ Not much to it at all. Wrap the list and make it scrollable. Then add scroll-snap-type .wrapper { scroll-snap-type: x mandatory; overflow-x: scroll; } Then make sure each list item has scroll-snap-align set on it li { scroll-snap-align: center; } That's it! Pretty cool demo to put together and see how to do this stuff with these APIs ๐Ÿค“ A lot of cool little tricks to pick up for writing your CSS! โญ๏ธ CodePen.IO link below! ๐Ÿ‘‡

jhey ส•โ€ขแดฅโ€ขส”

234,583 views โ€ข 3 years ago

CSS Trick ๐Ÿค™ You can use scroll-driven animations on the inline axis to create list animations like in these cards ๐Ÿซถ article { animation: vibe; animation-timeline: view(inline); animation-range: cover 40% cover 60%; } @โ€‹keyframes vibe { 50% { scale: 1; filter: grayscale(0); }} Here you use a view() timeline with the inline axis set inside the function. This means you can hook into the horizontal scroll position of an element inside its scroller ๐Ÿ™Œ In this demo, you set a default smaller scale and make each card grayscale ๐Ÿค article { scale: 0.8; filter: grayscale(1); } Then the animation happens as each card enters from the right at 0% and leaves to the left at 100% ๐ŸŽž๏ธ 50% is the halfway point and in your keyframes you make each card grow and saturate at that point before returning to its original state โœจ scroll-snap provides a nice look-and-feel here and on mobile ๐Ÿซฐ It's really as straightforward as that but made so much easier with a few lines of CSS ๐Ÿ’™ For the parallax effect, you can animate a background-position on the card or the object-position on an img depending on what you go with ๐Ÿค™ Lastly, you can use this today with progressive enhancement by wrapping your scroll-driven animation code in @โ€‹supports and @โ€‹media โšก๏ธ Users without support still get a decent experience! CodePen.IO link below! ๐Ÿ‘‡

jhey ส•โ€ขแดฅโ€ขส”

465,626 views โ€ข 2 years ago