UNPKG

framer-motion

Version:

A simple and powerful JavaScript animation library

27 lines (24 loc) 856 B
import { easingDefinitionToFunction } from '../../easing/utils/map.mjs'; function getOriginIndex(from, total) { if (from === "first") { return 0; } else { const lastIndex = total - 1; return from === "last" ? lastIndex : lastIndex / 2; } } function stagger(duration = 0.1, { startDelay = 0, from = 0, ease } = {}) { return (i, total) => { const fromIndex = typeof from === "number" ? from : getOriginIndex(from, total); const distance = Math.abs(fromIndex - i); let delay = duration * distance; if (ease) { const maxDelay = total * duration; const easingFunction = easingDefinitionToFunction(ease); delay = easingFunction(delay / maxDelay) * maxDelay; } return startDelay + delay; }; } export { getOriginIndex, stagger };