Loading video...

Video Failed to Load

Go Home

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 {...

232,131 views โ€ข 2 years ago โ€ขvia X (Twitter)

11 Comments

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

Here's that @CodePen link! ๐Ÿš€ You need to be in Chrome to see this in action ๐Ÿ“œ But, how cool? CSS only list animations that could work as a progressive enhancement โœจ If they aren't supported, your user still gets a good experience ๐Ÿ™Œ

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

And here's the original piece of UI from the iPhone 15 Pro page ๐Ÿค™ The CodePen demo isn't quite as "polished". But, it's proving the concept of what we can achieve ๐Ÿ”ฅ The iPhone page uses JavaScript to update the transform matrix of the images via inline styles as you scroll. Think if you mess with the timing a little, it could be spot-on in the CSS-only version ๐Ÿ’ฏ Maybe using some of the linear() stuff from recent weeks ๐Ÿค”

Tim Okonkwo โš›๏ธ's profile picture
Tim Okonkwo โš›๏ธ2 years ago

This guy makes me feel I didnโ€™t learn CSS ๐Ÿ˜‚

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

Haha โ€“ You now CSS ๐Ÿ˜‰ But, it's constantly evolving.

Oscar Cornejo's profile picture
Oscar Cornejo2 years ago

๐Ÿ‘๐Ÿผ๐Ÿ‘๐Ÿผ๐Ÿ™Œ๐Ÿผ

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

Thanks Oscar ๐Ÿ™

๐Ÿ‘จโ€๐Ÿ’ป damir.fun ๐Ÿ˜Ž's profile picture
๐Ÿ‘จโ€๐Ÿ’ป damir.fun ๐Ÿ˜Ž2 years ago

CSS scroll snap is insanely powerful

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

The undercover goat ๐Ÿ๐Ÿ˜…

Nikola Lakovic's profile picture
Nikola Lakovic2 years ago

๐Ÿคฏ

Helios Dev's profile picture
Helios Dev2 years ago

Sick! Would there be any possibility to start them from display none as well? Could create a โ€œlazy loaderโ€ purely with CSS, as I recall the browser doesnโ€™t load resources such as images when itโ€™s set to display: none. Maybe in combination with :has and :visible.

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

I need to revisit this demo today ๐Ÿคž Wanted to add an intro animation to it too. One trick here is that it's all the same image for this purpose but cropped with object-view-box. Perhaps, animating stepped with display and using a preload perhaps ๐Ÿค”That's off the top of my head

Related Videos

CSS Trick! โšก๏ธ You can use scroll-driven animation with background-attachment to create a dynamic glowing card scroller without JS ๐Ÿ”ฅ section { animation:vibe; animation-timeline:--list; } @โ€‹keyframes vibe { to{--hue:320;}} .glow {background: hsl(var(--hue) 80% 50%);} Here's how! ๐Ÿค™ You can use the background-attachment trick used in other glow card demos ๐Ÿ˜Ž article { background-attachment: fixed; } The difference here is that you aren't going to update the fixed background position with your pointer this time. It can remain fixed. The magic part is that as you scroll, the background will leave the card that's leaving and enter the card that's entering โœจ For the extra background glow, you can use a fixed pseudo element on the list container itself ๐Ÿ’ช Once that's in place, you're only task is to change the color of the background as you scroll ๐Ÿค” Create a custom property declaration for the --hue @โ€‹property --base { inherits: true; syntax: ' '; initial-value: 0; } Then create an animation that updates this value @โ€‹keyframes accent { to { --hue: 320; }} The last piece is hooking it up to scroll and there is a little trick in here ๐Ÿ‘€ First, you need an inline scroll-timeline on the list ul { scroll-timeline: --list inline; } Then you can use timeline-scope to hoist that scroll-timeline up so a parent can use it. You then animate the custom property on this element and let the value cascade down to the places that need it ๐Ÿ”ฅ section { timeline-scope: --list; animation: accent both linear; animation-timeline: --list; } For example, the glow uses the --hue this way [data-glow] { background-image: radial-gradient( 150px 150px at 50% 50%, hsl(var(--hue) 100% 70% / 0.25), transparent ); } Lastly, scroll-snap is optional of course but plays nice with the scroll-driven animation demos โœจ The key for that is ul { scroll-snap-type: x mandatory; } li { scroll-snap-align: center; } That's it! Pretty fun trick to play with! ๐Ÿค“ Any questions, let me know! Should we add it to the video walkthrough list? CodePen.IO link below! ๐Ÿ‘‡

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

116,462 views โ€ข 2 years ago

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,064 views โ€ข 2 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,170 views โ€ข 2 years ago