Hello,
I have a general question. How can I avoid redundant code (following DRY principles) using GSAP (especially ScrollTrigger)?
For example, the code below works just fine but It repeats 3 times and I don't want that. Isn't it possible to "store" the scrollTrigger information in a variable (since it's always the same) and apply it to the animations? I tried it with ScrollTrigger.create() but that doesn't work.
I'm pretty sure this topic is covered already, I just can't find it. Please just point me to it. I can solve it myself!
Thank you in advance!
gsap.from("#cloud-front", {
scrollTrigger: {
trigger: "#rocket-animation",
scrub: true,
start: "top 95%",
end: "top 5%",
markers: true
},
y: 160,
});
gsap.from("#cloud-back", {
scrollTrigger: {
trigger: "#rocket-animation",
scrub: true,
start: "top 95%",
end: "top 5%",
markers: true
},
y: 80,
});
gsap.from("#rocket", {
scrollTrigger: {
trigger: "#rocket-animation",
scrub: true,
start: "top 95%",
end: "top 5%",
markers: true
},
y: 240,
});