I'm trying to get the animation to scale up and down in a bouncy way using the animation timing function.
@keyframes iconEnter
0%
transform scale(0)
100%
transform scale(1)
animation-timing-function cubic-bezier(.1,.85,.1,1)
.icon
animation iconEnter 5s
This just scales linearly without the timing function being applied. What am I doing wrong?
Thanks.
The animation-timing-function specifies the speed curve of an animation. The speed curve defines the TIME an animation uses to change from one set of CSS styles to another. The speed curve is used to make the changes smoothly. Default value: ease.
Timing animation refers to how long an action takes from beginning to end. The functions of timing are to create movement that obeys the laws of physics, and to add interest to your animations.
CSS cubic-bezier() FunctionP0 is (0, 0) and represents the initial time and the initial state, P3 is (1, 1) and represents the final time and the final state. The cubic-bezier() function can be used with the animation-timing-function property and the transition-timing-function property.
There are 2 places where you can set a timing function: globally in the same place where you set the animation, or in the keyframes rule.
But, in the latter case, you have always n keyframes and n - 1 time intervals. IN your case, 2 keyframes and 1 time interval.
The timing function stated on a keyframe applies to the time interval that begins in this keyframe.
So, the correct way to apply a timing function on the keyframes would be on the first one:
@keyframes iconEnter {
0% {
transform: scale(0.1);
animation-timing-function: cubic-bezier(.25,8,.25,-8);
}
100% {
transform: scale(1);
}
}
div {
width: 100px;
height: 100px;
margin: 100px;
background-color: tomato;
transform: scale(0.1);
}
body:hover div {
animation: iconEnter 4s forwards;
}
<div></div>
Not sure what you are expecting with the time function; it's working for me on Chrome 59.
That being said...
I am able to get the desired result using keyframes, TranslateX and scale
The code can be greatly shortened but I left everything there for demo purposes.
(rough) Working example:
@keyframes iconEnter {
0% {
transform: scale(0)
}
10% {
transform: scale(0.1) translatey(30px)
}
20% {
transform: scale(0.2) translatey(-30px)
}
30% {
transform: scale(0.3) translatey(30px)
}
40% {
transform: scale(0.4) translatey(-30px)
}
50% {
transform: scale(0.5) translatey(30px)
}
60% {
transform: scale(0.6) translatey(-30px)
}
70% {
transform: scale(0.7) translatey(30px)
}
80% {
transform: scale(0.8) translatey(-30px)
}
90% {
transform: scale(0.9)translatey(30px)
}
100% {
transform: scale(1) translatey(0deg)
}
}
.icon {
animation: iconEnter 10s;
border-radius: 100vw;
animation-timing-function: cubic-bezier(0.86, 0, 0.07, 1)
}
<img src="https://unsplash.it/100/100" class="icon">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With