Smooth Easing
Smooth Easing
Section titled “Smooth Easing”Introduction
Section titled “Introduction”Easing functions make animations feel more natural by varying the speed over time — accelerating, decelerating, or bouncing.
Easing Function
Section titled “Easing Function”function easeInOut(t) { return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;}Complete Easing Animation
Section titled “Complete Easing Animation”function animateWithEasing(element, duration) { const start = performance.now(); const startX = 0; const endX = 500;
function frame(now) { const elapsed = now - start; const progress = Math.min(elapsed / duration, 1); const easedProgress = easeInOut(progress);
element.style.transform = `translateX(${startX + (endX - startX) * easedProgress}px)`;
if (progress < 1) { requestAnimationFrame(frame); } }
requestAnimationFrame(frame);}
animateWithEasing(element, 1000); // 1 second animationCommon Easing Functions
Section titled “Common Easing Functions”const easing = { linear: t => t, easeIn: t => t * t, easeOut: t => t * (2 - t), easeInOut: t => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t, bounce: t => { const n = 7.5625; const d = 2.75; if (t < 1 / d) return n * t * t; if (t < 2 / d) return n * (t -= 1.5 / d) * t + 0.75; if (t < 2.5 / d) return n * (t -= 2.25 / d) * t + 0.9375; return n * (t -= 2.625 / d) * t + 0.984375; }};Summary
Section titled “Summary”- Easing makes animations feel natural
easeInOutaccelerates then decelerateseaseOutstarts fast, slows at end- Common pattern: calculate progress (0-1), apply easing, interpolate value