Understanding `-sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in;
These CSS custom properties and a shorthand-style declaration define a simple, reusable animation pattern that can be applied to elements for a smooth fade-in effect. Below is a concise guide explaining each part, how to implement it, and practical examples.
What each part means
- -sd-animation: sd-fadeIn;
- Acts like a custom “animation name” hook used by your CSS/JS system. It signals that the element should use the
sd-fadeInanimation pattern.
- Acts like a custom “animation name” hook used by your CSS/JS system. It signals that the element should use the
- –sd-duration: 250ms;
- A CSS custom property specifying the animation’s duration. Using a variable makes it easy to adjust timing across components.
- –sd-easing: ease-in;
- A CSS custom property for the timing function, controlling acceleration.
ease-instarts slow and speeds up.
- A CSS custom property for the timing function, controlling acceleration.
Core CSS pattern
Use CSS variables and an @keyframes rule tied to the sd-fadeIn name. Example:
css
:root {–sd-duration: 250ms; –sd-easing: ease-in;}
@keyframes sd-fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); }}
/* A utility that applies the animation when -sd-animation is set */[data-sd-animation=“sd-fadeIn”],.-sd-animation-sd-fadeIn { animation-name: sd-fadeIn; animation-duration: var(–sd-duration, 250ms); animation-timing-function: var(–sd-easing, ease-in); animation-fill-mode: both; will-change: opacity, transform;}
How to apply in HTML
- Using a data attribute:
html
<div data-sd-animation=“sd-fadeIn”>Fade-in content</div>
- Using a utility class:
html
<div class=”-sd-animation-sd-fadeIn” style=”–sd-duration: 400ms; –sd-easing: cubic-bezier(.2,.8,.2,1);”> Slower, custom easing</div>
JavaScript trigger (optional)
If you want to add the animation after mount or on interaction:
js
function triggerFadeIn(el, duration = ‘250ms’, easing = ‘ease-in’) { el.style.setProperty(’–sd-duration’, duration); el.style.setProperty(’–sd-easing’, easing); el.setAttribute(‘data-sd-animation’, ‘sd-fadeIn’); // force reflow to restart animation if needed void el.offsetWidth;}
Accessibility tips
- Keep motion-reduction preferences in mind:
css
@media (prefers-reduced-motion: reduce) { [data-sd-animation=“sd-fadeIn”], .-sd-animation-sd-fadeIn { animation: none !important; transition: none !important; }}
- Use short durations (like 250ms) for quick, non-disruptive motion.
Use cases
- Toasts and notifications
- Modal or panel entrance
- Staggered list reveal (combine with animation-delay)
- Micro-interactions on hover/focus (adjust transform and easing)
Stagger example
css
.item { opacity: 0; transform: translateY(6px); }.item[data-sd-animation=“sd-fadeIn”] { animation: sd-fadeIn var(–sd-duration) var(–sd-easing) both; }
.item:nth-child(1) { animation-delay: 0ms; }.item:nth-child(2) { animation-delay: 60ms; }.item:nth-child(3) { animation-delay: 120ms; }
Summary
The snippet -sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in; encapsulates a compact, customizable fade-in animation pattern. Implement it with CSS variables, respect reduced-motion preferences, and use short durations for unobtrusive UI motion.
Leave a Reply