Capítulo 167 de 411
A lightweight helper implementing the FLIP technique (First-Last-Invert-Play) for animating elements to their new position after a DOM change, for cases too simple to justify the full Flip plugin.
flip(elements, changeFunc, vars) — records each element's bounding box, calls changeFunc() to perform the actual DOM change, then tweens x/y from the old position to the new one.vars supports duration, stagger, ease, onComplete, delay._flip reference per element so overlapping calls fast-forward any in-progress FLIP first.function flip(elements, changeFunc, vars) {
elements = gsap.utils.toArray(elements);
vars = vars || {};
let tl = gsap.timeline({ onComplete: vars.onComplete, delay: vars.delay || 0 }),
bounds = elements.map((el) => el.getBoundingClientRect()), copy = {}, p;
elements.forEach((el) => { el._flip && el._flip.progress(1); el._flip = tl; });
changeFunc();
for (p in vars) if (p !== "onComplete" && p !== "delay") copy[p] = vars[p];
copy.x = (i, element) => "+=" + (bounds[i].left - element.getBoundingClientRect().left);
copy.y = (i, element) => "+=" + (bounds[i].top - element.getBoundingClientRect().top);
return tl.from(elements, copy);
}
x/y translation.