iHateReading
CSS is evolving
This article demonstrates how CSS's new `animation-timeline` property simplifies scroll-triggered animations, improving performance over JavaScript solutions. Using `animation-timeline: scroll()`, a scroll progress bar is created with just a few lines of CSS, animating a `scaleX` transformation. Similarly, `animation-timeline: view()` is used to animate an element's appearance (`slideIn` animation) when it enters the viewport. The article highlights the performance benefits of using CSS for these animations compared to JavaScript.
Copy HTML
Copy Markdown
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
.footer::after {
content: "";
position: fixed;
bottom: 0;
left: -2px;
width: 100%;
height: 0.8em;
background-color: rgb(0, 0, 0);
transform-origin: left;
border-top-right-radius: 20px;
border-bottom-right-radius: 20px;
animation: progress-width linear;
animation-timeline: scroll();
animation-range: 0 100%;
}
@keyframes progress-width {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
img {
animation: slideIn;
animation-timeline: view();
animation-range: 0% 50%;
}
@keyframes slideIn {
0% {
transform: translateX(100%);
opacity: 0;
}
100% {
transform: translateX(0%);
opacity: 1;
}
}
Subscribe
iHateReading
A platform by a developer for a developer
Products
Policies
Contact us
iHateReading
Please login to leave a comment