Hi, I'm struggling to create a fade in/out animation to a pinned section using GSAP's horizontal scroll. What I'm trying to do is to fade in/out between sections, mainly the content and the background or an image inside each sections.
I tried using this code function:
function setSection(newSection) {
if (newSection !== currentSection) {
var tl = gsap.timeline();
tl.to(".col-fade", { y: -30, autoAlpha: 0, duration: 0.3 });
tl.to(currentSection, { autoAlpha: 0, duration: 0.5 });
var tl = gsap.timeline();
tl.to(newSection, { autoAlpha: 1, duration: 0.5 });
tl.to(".col-fade", { y: -30, autoAlpha: 1, duration: 0.3 });
currentSection = newSection;
}
}
and set it to gsap.to(sections, {}); function like this:
gsap.to(sections, {
xPercent: -100 * (sections.length - 1),
ease: "none",
scrollTrigger: {
trigger: ".container",
pin: true,
scrub: 1,
snap: 1 / (sections.length - 1),
end: () => "+=" + document.querySelector(".container").offsetWidth
},
onToggle: (self) => self.isActive && setSection(sections)
});
However, it doesn't seem to have an effect. Any Idea why I'm not able to successfully solve the issue? I'm still learning GSAP`s up to this point. Any ideas would be a great help. Thanks a lot.