Let CSS know when you scroll. No JavaScript needed. Scroll-state queries let you style elements based on how a container is scrolled. You can detect when it’s at the top, bottom, or in motion, and trigger animations directly from CSS. Here’s a simple example: html { container-type: scroll-state; container-name: scroller; } .to-top { position: fixed; bottom: 20px; right: 20px; translate: 80px 0; transition: all 0.4s ease; } @container scroller scroll-state(scrollable: top) { .to-top { translate: 0 0; } } The key is `container-type: scroll-state`. It makes the page a scroll container that CSS can observe. The `@container` rule reacts to its scroll state. When the container is at the top, bottom, or being scrolled, styles update automatically. No scroll listeners. No intersection observers. Just CSS responding to motion. You can use it to fade headers, slide elements, or trigger transitions as users scroll. Browser support is about 68.5%, so it’s still experimental, use with caution (or don't use it yet). This is a glimpse of a more reactive CSS. Less scripting, more design freedom. And if you wanna grasp what's possible to do with modern CSS... I created a small 7-day email course to help you with that... Here's the link: https://lnkd.in/ezBJUPQK
I really like this but alas it's not ready for production. I get by with a very simple javascript function that toggles a class for top-most position, scrolled, and scrolling upward. That way the styling stays within CSS.
Good
Very nice…
Great!
Amazing!
Be careful with the browser support.
Step by step guide for CSS scroll Feature and how to implement them. https://www.garudax.id/posts/zain-sher_new-css-scroll-features-will-replace-javascript-activity-7421781694535544832-68_B?utm_source=share&utm_medium=member_android&rcm=ACoAAC6tZqgBnwMZxouJcyLGoOImiP3DCtEX-bo
👇 Live demo + source code scroll-state(scrollable:top) 👇 🔗 CodePen Demo: https://codepen.io/zain-muhammad/pen/xbOggzJ 🔗 GitHub Repo: https://github.com/Zain-Muhammad/NEW-CSS-Scroll-Feature-Manage-Visibility-on-scroll-Without-Javascript
got into CSS scroll driver animations on one of my projects, the task was to reveal cards on scroll one by one (to force user to see information before scrolling to the bottom of the page). Took me a white to get it right.. 🫣 I used Framer Motion though, excited to get more into CSS scroll driver animations
Oh very cool, I was coding this just a couple of weeks ago