Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Set animation with a slow end using CSS
The CSS animation-timing-function property with the ease-out value is used to create animations that start fast and slow down towards the end. This creates a natural deceleration effect, making animations feel more realistic and smooth.
Syntax
selector {
animation-timing-function: ease-out;
}
Possible Values
| Value | Description |
|---|---|
ease-out |
Animation starts fast and slows down at the end |
ease-in |
Animation starts slow and speeds up |
ease-in-out |
Animation starts slow, speeds up, then slows down |
linear |
Animation maintains constant speed |
Example
The following example demonstrates an animation with a slow end using ease-out timing function −
<!DOCTYPE html>
<html>
<head>
<style>
.container {
width: 400px;
height: 200px;
border: 2px solid #ccc;
position: relative;
margin: 20px;
}
.box {
width: 80px;
height: 80px;
background-color: #4CAF50;
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
color: white;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
animation: moveRight 3s ease-out infinite alternate;
}
@keyframes moveRight {
from {
left: 0;
}
to {
left: 300px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="box">ease-out</div>
</div>
</body>
</html>
A green box moves from left to right inside a bordered container. The animation starts fast and gradually slows down as it approaches the right side, creating a natural deceleration effect. The animation repeats in reverse.
Comparison with Other Timing Functions
Here's a visual comparison showing different timing functions −
<!DOCTYPE html>
<html>
<head>
<style>
.demo-container {
width: 350px;
margin: 10px 0;
border: 1px solid #ddd;
padding: 10px;
}
.timing-box {
width: 50px;
height: 50px;
background-color: #FF6B6B;
margin: 5px 0;
color: white;
display: flex;
align-items: center;
justify-content: center;
font-size: 10px;
position: relative;
animation-duration: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-name: slide;
}
.ease-out { animation-timing-function: ease-out; }
.linear { animation-timing-function: linear; }
.ease-in { animation-timing-function: ease-in; }
@keyframes slide {
from { left: 0; }
to { left: 280px; }
}
</style>
</head>
<body>
<div class="demo-container">
<h4>Animation Timing Comparison</h4>
<div class="timing-box ease-out">ease-out</div>
<div class="timing-box linear">linear</div>
<div class="timing-box ease-in">ease-in</div>
</div>
</body>
</html>
Three red boxes move horizontally with different timing functions. The "ease-out" box starts fast and slows down at the end, "linear" maintains constant speed, and "ease-in" starts slow and speeds up. The difference in deceleration patterns is clearly visible.
Conclusion
The ease-out timing function creates natural-looking animations by starting fast and gradually slowing down. This timing function is ideal for exit animations and UI transitions where you want smooth deceleration.
Advertisements
