-sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in;
These custom CSS properties offer a compact, reusable way to define a simple fade-in animation. Below is a concise guide covering what each property does, how to implement them, and tips for practical use.
What they mean
- -sd-animation: sd-fadeIn; — selects a named animation (here, “sd-fadeIn”) that will be applied.
- –sd-duration: 250ms; — sets the animation length to 250 milliseconds.
- –sd-easing: ease-in; — sets the animation timing function to ease-in (starts slow, then accelerates).
Example implementation
- Define the CSS custom properties and animation keyframes:
css
:root {–sd-duration: 250ms; –sd-easing: ease-in; -sd-animation: sd-fadeIn;}
@keyframes sd-fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); }}
- Apply them to an element, using the shorthand animation property:
css
.fade-in { animation-name: var(-sd-animation); animation-duration: var(–sd-duration); animation-timing-function: var(–sd-easing); animation-fill-mode: both;}
- HTML:
html
<div class=“fade-in”>Content that fades in</div>
Variations & tips
- Use different durations (e.g., 150ms for micro-interactions, 400–600ms for more prominent entrances).
- Combine easing functions:
cubic-bezier(…)for custom motion. - Add
animation-delayfor staggered sequences. - Prefer
transformandopacityfor performant animations (GPU-accelerated). - Use
prefers-reduced-motionmedia query to disable or simplify animations for accessibility:
css
@media (prefers-reduced-motion: reduce) { .fade-in { animation: none; opacity: 1; transform: none; }}
When to use
- Micro-interactions (toasts, modals, subtle entrance effects).
- Loading states where content should gently appear.
- Enhancing perceived responsiveness without overwhelming users.
Summary
These variables make a consistent fade-in effect easy to apply and adjust across a site. Define keyframes once, tune duration and easing via custom properties, and respect accessibility preferences for the best user experience.
Leave a Reply