I have a basic gsap animation set up with matchMedia.
ScrollTrigger.matchMedia({
"(min-width: 700px)": function () {
let containerWidth = parseInt(getComputedStyle(document.querySelector(".see-through")).width);
let tl = gsap.timeline({
scrollTrigger: {
/ ....
}
});
tl.to(".logo-transparent", {
x: containerWidth/2,
scale: "0.8"
});
},
"(max-width: 699px)": function () {
let containerHeight = parseInt(getComputedStyle(document.querySelector(".see-through")).height);
let tl = gsap.timeline({
scrollTrigger: {
/ ....
}
});
tl.to(".logo-transparent", {
y: containerHeight/2,
scale: "0.9"
})
}
});
Now what I want is to update the values of containerWidth and containerHeight on each resize event. I tried adding an eventListener for resize event and updating the variables, but it still has no effect on the animation.
Perhaps the animation is not updated on each resize unless the media breakpoints change.
What approach can I follow for the desired effect?
As I understand the documentation on https://greensock.com/docs/v3/Plugins/ScrollTrigger/static.addEventListener() there is an event of
ScrollTriggeryou can listen to:I would also suggest to intiate your
tlvariable outside of theScrollTriggerblock.So you might try something like this: