Const
The HTML element to animate
CSS properties to animate
Animation duration in milliseconds (default: 300)
CSS easing function (default: 'ease')
Promise that resolves when animation completes
const element = document.querySelector('.box');
await AnimationUtils.animate(element, {
transform: 'translateX(100px)',
opacity: '0.5'
}, 500, 'ease-in-out');
Animates an element using requestAnimationFrame for smoother animations
The HTML element to animate
CSS properties to animate
Animation duration in milliseconds (default: 300)
Custom easing function (default: linear)
Promise that resolves when animation completes
const element = document.querySelector('.box');
await AnimationUtils.animateWithRAF(element, {
transform: 'translateX(100px)'
}, 500, (t) => t * t); // Quadratic easing
Creates a keyframe animation using the Web Animations API
The HTML element to animate
Array of keyframe objects
Animation options
Animation object
const element = document.querySelector('.box');
const animation = AnimationUtils.createKeyframeAnimation(element, [
{ transform: 'translateX(0)', opacity: 1 },
{ transform: 'translateX(100px)', opacity: 0.5 }
], {
duration: 500,
easing: 'ease-in-out'
});
Creates a spring physics-based animation
The HTML element to animate
CSS properties to animate
Spring animation configuration
Promise that resolves when animation completes
const element = document.querySelector('.box');
await AnimationUtils.createSpringAnimation(element, {
transform: 'translateY(200px)'
}, {
stiffness: 170,
damping: 26,
mass: 1
});
Gets all animations currently running on an element
The HTML element to check
Array of Animation objects
const element = document.querySelector('.box');
const animations = AnimationUtils.getAnimations(element);
Gets the current animation state of an element
The HTML element to check
Current animation state: 'idle', 'running', or 'paused'
const element = document.querySelector('.box');
const state = AnimationUtils.getAnimationState(element);
if (state === 'running') {
console.log('Element is currently animating');
}
Checks if an element has any active animations
The HTML element to check
True if the element has any animations
const element = document.querySelector('.box');
if (AnimationUtils.hasAnimations(element)) {
console.log('Element has active animations');
}
Waits for all animations on an element to complete
The HTML element to wait for
Promise that resolves when all animations complete
const element = document.querySelector('.box');
await AnimationUtils.waitForAnimations(element);
console.log('All animations completed');
Animates an element using CSS transitions