Skip navigation
Fade elements in and out on scroll in a window with CSS? ✅
0:00 / 0:36

Fade elements in and out on scroll in a window with CSS? ✅

jhey ʕ•ᴥ•ʔ

@jh3yy146K followers

Visit on X
1,935 likesDownloadOriginal post

222,957 views

Fade elements in and out on scroll in a window with CSS? ✅ ul { scroll-padding-inline: 200px; } article { animation: highlight; animation-timeline: view(inline); } @​keyframes highlight { entry 0%, exit 100% { opacity: 0; } entry 100%, exit 0% { opacity: 1; } } cc Adam Wathan

10 Comments

Comments from the original post on X (Twitter)

  • Mykyta Batrak 🇺🇦's profile picture

    @mykytabatrak

    @adamwathan So cool! I was going through @bramus scroll-driven demos and had keyframe ranges but I couldn't understand how to account for the padding. Turns out scroll-padding is the solution 🤯, you are a genius!

    6 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    @adamwathan @bramus Yeah, looks like that will do it 🤙 As mentioned, it was late for me last night 😅 Knew there was a cleaner way but mind was blanking haha Glad we got there in the end! I'll do some write ups on all these things soon 🔜

    3 likes

  • Matias Baldanza.dev 😁 ⚛️'s profile picture

    @matiasbaldanza

    @adamwathan This is so much better than what I used to do: :before and :after div with a gradient from transparent to background, absolutely positioned over the edges of the carousel.

    3 likes

  • Joshua Soileau's profile picture

    @joshua_soileau

    @adamwathan Now do it with Tailwind!

    2 likes

  • leblanc meneses's profile picture

    @leblancmeneses

    @adamwathan I didn't think it was possible without js. awesome work with so little code.

    2 likes

  • AI Developer | Fullstack Dev | Kelvin Dim's profile picture

    @KelvinDimson

    @adamwathan This mf!!!!!

    1 like

  • Esso⚡️'s profile picture

    @_vick_thor

    @adamwathan Can you please drop codepen link 😩😩😩😩

    1 like

  • toddmorey's profile picture

    @toddmorey

    @adamwathan Unfortunately not yet supported on FF / Safari just yet. But still works as progressive enhancement!

    1 like

  • Januario's profile picture

    @JanuarioPinto_

    @adamwathan Stuff like this would be good for the course 💯 I think it would probably be a good idea to include the tailwind version of animations too, as tailwind is obviously pretty famous (and very handy in react/next), I think that practically speaking, a lot would benefit from it.

    1 like

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    @adamwathan the amount of overhead to recreate everything I build in Tailwind too is not something I'm overly into if I'm honest

    2 likes