OK, obviously not working as expected (sigh, I seriously don't know why I keep having these kind of problems). Now, it seems that the 'final' step is triggered immediately no matter WHAT the counter says.
I do the following:
var maxLoops = 3;
var loopCount = 0;
function fadeOut () {
let tl_fadeout = gsap.timeline();
tl_fadeout.fromTo(header.chars, .1, { opacity: 1 }, { opacity: 0 });
return tl_fadeout;
}
function isFinalLoop () {
loopCount++;
if ( loopCount == maxLoops ) {
main_tl.pause();
}
}
main_tl
.add( getHeader() )
.add( bilforsikringFadeIn(), "-=1" )
.add( turnOnEl(), "+=1" )
.add( turnOffEl(), "+=3" )
.add( bilforsikringOff(), "-=1" )
.add( getHybrid(), "-=0" )
.add( bilforsikringOn(), "-=0" )
.add( getTextContainer(), "+=2" )
.add( getCta(), "-=.2" )
.call( isFinalLoop )
.add( fadeOut() );
Now, WHY on earth does the 'fadeOut' get triggered immediately? It runs 'on top of' the first 'getHeader' timeline as is the best way I can describe it (it seems it both fades in and out at the same time ) ... this is driving me absolutely bunkers now ...