For example, I have this animation
@keyframes fade-out-50-in-70 {
0% { opacity: 1; }
50% { opacity: 0; }
70% { opacity: 1; }
100% { opacity: 1; }
}
.animate-fade-out-in {
animation-name: fade-out-50-in-70;
animation-timing-function: linear;
}
try to use this linear (linear(0, 0.5 35%, 1 70%);
)function to achieve same thing
@keyframes fade-out-in {
0% { opacity: 1; }
50% { opacity: 0; }
100% { opacity: 1; }
}
.animate-fade-out-in-2 {
animation-name: fade-out-in;
animation-timing-function: linear(0, 0.5 35%, 1 70%);
}
But I failed. how can I turn that into success?
div {
background: red;
width: 100px;
aspect-ratio: 1/1;
}
@keyframes fade-out-50-in-70 {
0% { opacity: 1; }
50% { opacity: 0; }
70% { opacity: 1; }
100% { opacity: 1; }
}
.animate-fade-out-in {
animation-name: fade-out-50-in-70;
animation-timing-function: linear;
animation-duration: 2s;
animation-iteration-count: infinite;
}
@keyframes fade-out-in {
0% { opacity: 1; }
50% { opacity: 0; }
100% { opacity: 1; }
}
.animate-fade-out-in-2 {
animation-name: fade-out-in;
animation-timing-function: linear(0, 0.5 35%, 1 70%);
animation-duration: 2s;
animation-iteration-count: infinite;
}
<div class="animate-fade-out-in">by @keyframes</div>
<div class="animate-fade-out-in-2">by timing fn</div>
2
Answers
Make the keyframes easy by using
100%
foropacity: 0
then thelinear()
function should also be easy to defineWhy don’t you use
cubic-bezier()
?