Capítulo 160 de 411
A helper that instantly changes one element's transformOrigin to match another element's, without the visual jump that normally happens when transformOrigin changes (requires MotionPathPlugin for coordinate conversion).
transformOrigin, converts those coordinates into the source element's space via MotionPathPlugin.convertCoordinates().x/y by the same amount to cancel out the jump.gsap.registerPlugin(MotionPathPlugin).function alignOrigins(fromElement, toElement) {
let [fromEl, toEl] = gsap.utils.toArray([fromElement, toElement]),
a = window.getComputedStyle(toEl).transformOrigin.split(" "),
newOrigin = MotionPathPlugin.convertCoordinates(toEl, fromEl, {
x: parseFloat(a[0]), y: parseFloat(a[1]),
}),
bounds1 = fromEl.getBoundingClientRect(), bounds2;
gsap.set(fromEl, { transformOrigin: newOrigin.x + "px " + newOrigin.y + "px" });
bounds2 = fromEl.getBoundingClientRect();
gsap.set(fromEl, {
x: "+=" + (bounds1.left - bounds2.left),
y: "+=" + (bounds1.top - bounds2.top),
});
}
transformOrigin mid-animation normally causes a jump unless the position is compensated like this.MotionPathPlugin.convertCoordinates() for the coordinate-space math.