Skip navigation
Future CSS Tip! 🍏 You can create this Apple-style photo scroller by combining CSS scroll-driven…
0:00 / 0:39

Future CSS Tip! 🍏 You can create this Apple-style photo scroller by combining CSS scroll-driven…

jhey ʕ•ᴥ•ʔ

@jh3yy149K followers

Visit on X
1,139 likesDownloadOriginal post

234,702 views

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! 👇

11 Comments

Comments from the original post on X (Twitter)

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    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 🙌

    27 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    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 🤔

    30 likes

  • Tim Okonkwo ⚛️'s profile picture

    @timokonkwo_

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

    3 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

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

  • Oscar Cornejo's profile picture

    @0scarCornejo

    👏🏼👏🏼🙌🏼

    2 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Thanks Oscar 🙏

    1 like

  • 👨‍💻 damir.fun 😎's profile picture

    @damdeez

    CSS scroll snap is insanely powerful

    1 like

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    The undercover goat 🐐😅

    1 like

  • Nikola Lakovic's profile picture

    @nikola_lakovic

    🤯

    1 like

  • Helios Dev's profile picture

    @HeliosCreator

    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.

    1 like

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    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

    1 like