Growing header
With the CSS Timeline API.
This title will become HUGE when you're scrolling down!
The steps
- Create the animation
- Create the CSS animation
- Add the animation to the element
- Attach the animation to the scroll-timeline
- Create a scroll timeline
- Add the animation-timeline to the element
- Set the animation range (when should it start and when should it end)
The code
First of all, the HTML
<div class="container">
<h2>
This title will become HUGE when you're scrolling down!
</h2>
... more content here.
</div>
1. Create the CSS animation
@keyframes grow-on-scroll {
from {
transform: scale(1);
}
to {
transform: scale(12);
}
}
.animated-title {
animation: grow-on-scroll linear forwards;
}
2.1 Create a scroll timeline
.container {
view-timeline-name: --growing-header;
}
2.2 Create a scroll timeline
.animated-title {
animation-timeline: --growing-header;
}
2.3 Set the animation range
.animated-title {
animation-range: 50vh 80vh;
}
The total CSS
@keyframes grow-on-scroll {
from {
transform: scale(1);
}
to {
transform: scale(12);
}
}
.container {
view-timeline-name: --growing-header;
}
.animated-title {
animation: grow-on-scroll linear forwards;
animation-timeline: --growing-header;
animation-range: 50vh 80vh;
}