Skip navigation
CSS Tip! 📜 You can create scroll-driven micro-interactions with animation-timeline and custom…
0:00 / 0:36

CSS Tip! 📜 You can create scroll-driven micro-interactions with animation-timeline and custom…

jhey ʕ•ᴥ•ʔ

@jh3yy149K followers

Visit on X
3,712 likesDownloadOriginal post

496,181 views

CSS Tip! 📜 You can create scroll-driven micro-interactions with animation-timeline and custom properties 🔥 .search { animation: shrink; animation-timeline: scroll(); animation-range: 0 calc(var(--header-height) * 0.5); } @​keyframes shrink { to { width: calc(100% - var(--button-size); } } The --header-height is being used to dictate the container height for the header. You can use that for the animation-range used across different scroll animations 🤙 For another example, you can animate the box-shadow reveal on the header once the search has stuck 🍡 header { animation: shadow; animation-timeline: scroll(); animation-range: var(--header-height) calc(var(--header-height) * 1.5); } @​keyframes shadow { to { box-shadow: 0 5px 10px hsl(0 0% 0%); } } Then you have the little extras! 🧸🎈 Everything powered by the scroll() animation-timeline which hooks into the page scroll. And then using the --header-height in the different animation-range ✨ Give it a try! ⭐️ CodePen.IO link below! 👇

10 Comments

Comments from the original post on X (Twitter)

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Here's that @CodePen link! 🚀 Will work in all browsers 🤙 Where CSS animation-timeline isn't supported, GSAP ScrollTrigger will do the work for you 😉 You get the smooth scrubbing with GSAP too 🤤

    84 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    This one's a little revisit of this conference demo 👇 Refreshed with the new CSS syntax and JS support for browsers that don't support the new scroll APIs 🤙

    24 likes

  • Tobechukwu's profile picture

    @TobyMac_

    Hey man, do you have an animation course or YouTube channel?

    4 likes

  • Agboola Temitope's profile picture

    @kaiser_major

    This things you do, can only be done by you. Been looking for a way to achieve this effect

    4 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    See any other fun scroll effects you like, tag me! 🤙

    3 likes

  • Nine's profile picture

    @ninecodes_

    Man you make me wanna go deeeeep into learning crazy css animations :D

    4 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    @abuzackariyya Do it! 💯⚡️ A lot of fun. Kinda how I got myself into web development. Came from Java to JavaScript. Played with 3D CSS and animation in my spare time to learn CSS 😅

    2 likes

  • Tech Foo's profile picture

    @iiiiiiaaaann

    banger

    3 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    🙏🙏🙏

    1 like

  • Gokul's profile picture

    @gokul_i

    🔥

    3 likes