Capítulo 351 de 411
Creates a coordinated group of ScrollTriggers (one for each target element) that batch their callbacks (onEnter, onLeave, etc.) within a certain interval, delivering a neat Array so that you can easily do something like create a staggered animation of all the elements that enter the viewport around the same time.
batchMax: 3 and then 9 elements all enter the viewport at roughly the same time, 3 batches would be created, thus the onEnter callback would get fired 3 times in quick succession (not waiting for the interval to elapse). If you have a responsive layout that may require changing of the batchMax when the page resizes, you can use a function instead that returns an Integer. That will get called whenever ScrollTrigger fires a "refresh" (which occurs when the viewport resizes, when an inactive tab becomes active, etc.). Like batchMax: () => { ...your logic here... return integer }batchMax is reached (whichever is first).ScrollTrigger.batch(".box", {
onEnter: (elements, triggers) => {
gsap.to(elements, { opacity: 1, stagger: 0.15 });
console.log(elements.length, "elements entered");
},
onLeave: (elements, triggers) => {
gsap.to(elements, { opacity: 0, stagger: 0.15 });
console.log(elements.length, "elements left");
},
});