Good afternoon,
I have a challenge and I can't seem to figure it out... I'm using ScrollMagic to create a Timeline a bit like https://scrollmagic.io/examples/advanced/section_wipes_manual.html. Except I'm trying to fade in and fade out my sections, the sections are stacked upon each other (position: absolute). The first section should be visible at the start, then fade out and the second section should fade in, etc, etc... The problem I'm running in right now is that section 2 and 3 start at te same time and not after each other. Could really use some help and an example would be great. I can't recreate my project on Codepen, because I'm using all sort of external plugins, like StimulusJS. But here's my code:
import { Controller } from 'stimulus';
import * as ScrollMagic from 'scrollmagic';
import { TweenMax, TimelineMax } from 'gsap';
import { ScrollMagicPluginGsap } from 'scrollmagic-plugin-gsap';
ScrollMagicPluginGsap(ScrollMagic, TweenMax, TimelineMax);
class SM extends Controller {
connect() {
const TWEEN_DURATION_PERCENTAGE = 4;
const controller = new ScrollMagic.Controller();
new ScrollMagic.Scene({
triggerElement: this.containerTarget,
triggerHook: 0,
duration: this.containerTarget.offsetHeight * TWEEN_DURATION_PERCENTAGE,
})
.setPin(this.containerTarget)
.addTo(controller);
this.sectionTargets.forEach((section, i) => {
const animation = new TimelineMax()
.to(section, 1, {
opacity: i === 0 ? 1 : 0,
delay: i * this.sectionTargets.length,
})
.to(section, 1, {
opacity: i === 0 ? 0 : 1,
delay: i * this.sectionTargets.length,
});
new ScrollMagic.Scene({
triggerElement: this.containerTarget,
triggerHook: 0,
offset: section.offsetHeight,
duration: this.containerTarget.offsetHeight * TWEEN_DURATION_PERCENTAGE,
})
.setTween(animation)
.addTo(controller);
});
}
}
SM.targets = [
'container',
'section',
];
export default SM;
I hope anyone could help me, I would really appreciate it!