motion
Version:
The Motion library for the web
24 lines (21 loc) • 953 B
JavaScript
import { animateStyle } from './animate-style.es.js';
import { getOptions } from './utils/options.es.js';
import { resolveElements } from './utils/resolve-elements.es.js';
import { createAnimationControls } from './utils/controls.es.js';
import { resolveOption } from '../../utils/stagger.es.js';
function animate(elements, keyframes, options = {}) {
elements = resolveElements(elements);
const animations = [];
const numElements = elements.length;
for (let i = 0; i < numElements; i++) {
const element = elements[i];
for (const key in keyframes) {
const valueOptions = getOptions(options, key);
valueOptions.delay = resolveOption(valueOptions.delay, i, numElements);
const animation = animateStyle(element, key, keyframes[key], valueOptions);
animation && animations.push(animation);
}
}
return createAnimationControls(animations);
}
export { animate };