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 link below! 👇
Are you currently hiring for a role that includes using Node.js? Reply with a link to the opening and any relevant context.
If you're not, we'd appreciate a retweet for visibility 💚