正在加载视频...

视频加载失败

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 次观看 • 2 年前 •via X (Twitter)

11 条评论

jhey ▲🐻🎈 的头像
jhey ▲🐻🎈2 年前

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 ▲🐻🎈 的头像
jhey ▲🐻🎈2 年前

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 ⚛️ 的头像
Tim Okonkwo ⚛️2 年前

This guy makes me feel I didn’t learn CSS 😂

jhey ▲🐻🎈 的头像
jhey ▲🐻🎈2 年前

Haha – You now CSS 😉 But, it's constantly evolving.

Oscar Cornejo 的头像
Oscar Cornejo2 年前

👏🏼👏🏼🙌🏼

jhey ▲🐻🎈 的头像
jhey ▲🐻🎈2 年前

Thanks Oscar 🙏

👨‍💻 damir.fun 😎 的头像
👨‍💻 damir.fun 😎2 年前

CSS scroll snap is insanely powerful

jhey ▲🐻🎈 的头像
jhey ▲🐻🎈2 年前

The undercover goat 🐐😅

Nikola Lakovic 的头像
Nikola Lakovic2 年前

🤯

Helios Dev 的头像
Helios Dev2 年前

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 ▲🐻🎈 的头像
jhey ▲🐻🎈2 年前

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

相关视频

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 次观看 • 2 年前

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 次观看 • 2 年前