Capítulo 171 de 411
A ScrollTrigger-aware helper that, given a set of target elements, returns a reusable lookup function: call it later with one of those elements to get the exact scroll position that would align it, correctly accounting for pinning and a containerAnimation (horizontal scroll setups).
ScrollTrigger per target (with refreshPriority: -10 so it doesn't interfere with the page's real triggers) purely to measure position.start (same syntax as any ScrollTrigger start value, default "top top"), pinnedContainer, containerAnimation.function getScrollLookup(targets, { start, pinnedContainer, containerAnimation }) {
let triggers = gsap.utils.toArray(targets).map((el) =>
ScrollTrigger.create({
trigger: el, start: start || "top top",
pinnedContainer, refreshPriority: -10, containerAnimation,
})
);
return (target) => {
let t = gsap.utils.toArray(target)[0],
trigger = triggers.find((tr) => tr.trigger === t);
return trigger ? trigger.start : console.warn("target not found", target);
};
}
getBoundingClientRect() offsets when pinning or horizontal containerAnimation scroll is involved — both change the naive math.