1.5 KiB
1.5 KiB
title, tags
| title | tags |
|---|---|
| Zoom In Zoom Out Animation | animation,beginner |
Performs a zoom in and zoom out animation on an element using CSS.
- Apply
animationproperty to the element you want animate. - Set
animation-durationproperty to1s. Theanimation-durationproperty sets the amount of time that an animation would complete in one cycle. Its value should be in seconds or milli seconds. - Set
animation-timing-functiontoease. Theanimation-timing-functionproperty sets the animation progress through the duration of each cycle. - Set
animation-iteration-counttoinfinite. Theanimation-iteration-countproperty sets the number of times an animation should be playing before it stops. - Create a keyframe named
zoomInZoomOutwhich is responsible for applying intermediate styles throughout the animation sequence. Describe what needs to be done at steps, like in our example at0%, at50%, and at100%. Usescaleand apply it totransformproperty inside the@keyframeswhich will gives us a smooth and ease zoom in and zoom out animation.
<div class="container">
<div class="box"></div>
</div>
.container {
padding: 50px;
}
.box {
width: 50px;
height: 50px;
background-color: green;
animation: zoomInZoomOut;
animation-duration: 1s;
animation-timing-function: ease;
animation-iteration-count: infinite;
}
@keyframes zoomInZoomOut {
0% {
transform: scale(1, 1);
}
50% {
transform: scale(1.5, 1.5);
}
100% {
transform: scale(1, 1);
}
}