A classic bouncing ball animation. It looks simple, but it's hard to make it look real. The physics changes the ball in small ways. Each version has the same phases: launch, apex, then three decaying bounces, with the ball squashing on every impact and the shadow shrinking as it rises.
0.00 / 2.00 S
@keyframes ball-y {
0% { transform: translateY(0);
animation-timing-function: cubic-bezier(.16,.62,.34,1) }
26% { transform: translateY(-150px);
animation-timing-function: cubic-bezier(.66,.02,.84,.4) }
48% { transform: translateY(0);
animation-timing-function: cubic-bezier(.16,.62,.34,1) }
62% { transform: translateY(-60px) }
/* …74% 82% 88% 92% 95% 100% */
}
/* Squash lands on contact: the two steps into a squash
ease in, every other step takes the rule's ease-out. */
@keyframes ball-squash {
0% { transform: scale(1.25, 0.75); }
6% { transform: scale(1, 1); }
30% { transform: scale(0.95, 1.05); }
46% { transform: scale(1, 1); animation-timing-function: ease-in; }
48% { transform: scale(1.2, 0.8); }
54% { transform: scale(1, 1); }
69% { transform: scale(0.95, 1.05); animation-timing-function: ease-in; }
74% { transform: scale(1.15, 0.85); }
80%,
100% { transform: scale(1, 1); }
}
/* Smaller and fainter the higher the ball is. */
@keyframes ball-shadow {
0%, 48%, 74%, 88%, 100% { transform: scale(1); opacity: .45 }
26% { transform: scale(.45); opacity: .12 }
62% { transform: scale(.72); opacity: .25 }
82% { transform: scale(.88); opacity: .35 }
}
.ball { animation: ball-y 2s linear infinite }
.squash { animation: ball-squash 2s ease-out infinite }
.shadow { animation: ball-shadow 2s linear infinite }Nothing to install, and it only animates transform and opacity, so the browser can run it on its own thread and keep it smooth while JavaScript is busy.
Each keyframe's timing is a percentage of a total I work out by hand, so changing the duration means redoing all of them. And transform is one property, so I had to nest two elements to move and squash the ball separately.
9 keyframes · per-frame cubic-bezier
Loading engines…