Thank you for your prompt response and the suggestion! I was unaware that I could use matchMedia in this scenario.
I've modified the code accordingly, and the link remains unchanged from before.
useLayoutEffect(() => {
const mm = gsap.matchMedia();
const selector = gsap.utils.selector('#container');
const firstColumnItems = selector('#column-01 > *');
const secondColumnItems = selector('#column-02 > *');
const [item] = selector('#column-01 > div:first-child');
const paddingBottom = +gsap.getProperty(item, 'marginBottom');
const wholeItems = [...secondColumnItems, ...firstColumnItems];
mm.add(
{
isOneColumn: '(max-width: 727px)',
isTwoColumn: '(min-width: 728px)',
},
(context) => {
const { conditions } = context;
if (conditions?.isOneColumn) {
const wholeItemsLoop = verticalLoop(wholeItems, {
paused: true,
repeat: -1,
speed: 1,
paddingBottom,
reversed: false,
});
wholeItemsLoop.play();
return () => wholeItemsLoop.kill();
}
if (conditions.isTwoColumn) {
const firstColumnLoop = verticalLoop(firstColumnItems, {
paused: true,
repeat: -1,
speed: 0.9,
paddingBottom,
reversed: false,
});
const secondColumnLoop = verticalLoop(secondColumnItems, {
paused: true,
repeat: -1,
speed: 1,
paddingBottom,
reversed: false,
});
firstColumnLoop.play();
secondColumnLoop.play();
return () => {
firstColumnLoop.kill();
secondColumnLoop.kill();
};
}
},
root
);
return () => mm.revert();
}, []);
However, this resulted in the following error:
Error in /turbo_modules/gsap@3.12.2/dist/gsap.js (1325:29)
Maximum call stack size exceeded
Interestingly, when I comment out the repeat: -1, it works as intended. However, it only runs once, which is not the behavior I'm aiming for. Do you think I might have misused the matchMedia method? Your assistance is greatly appreciated. Thank you.