Hello,
I'm new to GSAP, so I apologize in advance if my problem could have been solved simply.
I have an HTML structure that looks like this:
<div class="chapter chapter-1">
<div class="page page-1">
<div class="sheet">
<p class="storyline">Lorem ipsum dolor sit amet consectetur adipisicing elit. Adipisci commodi optio fugiat eum porro provident necessitatibus vitae. Quis, doloremque inventore recusandae aperiam dolore adipisci blanditiis est dolorum architecto dicta quasi?</p>
<i class="fa-solid fa-circle-left reading-btn previous-chapter"></i>
<i class="fa-solid fa-circle-chevron-right reading-btn next-page"></i>
</div>
</div>
Of course, there are several chapters (chapter-1, chapter-2, ...) which themselves have several pages (page-1, page-2, ...).
I'd like to run a SplitType animation on my <p class="storyline"> each time it or its parent <div class="sheet"> enters the viewport.
To achieve this, I wrote the following code:
for (let indexPage = 0; indexPage < storyLines.length; indexPage++) {
const numPage = indexPage + 1;
console.log('Chapter ' + numChapter);
console.log('Page ' + numPage);
// I used this console.log only to make sure I had the right chapter and page number
const line = new SplitType(`.chapter-${numChapter} .page-${numPage} .storyline`, { types: 'chars' });
gsap.fromTo(`.chapter-${numChapter} .page-${numPage} .char`,
{
y: 100,
opacity: 0
},
{
y: 0,
opacity: 1,
stagger: 0.1,
duration: 3,
delay: 3,
ease: 'power4.out',
scrollTrigger: {
trigger: `.chapter-${numChapter} .page-${numPage} .storyline`,
toggleActions: "play none reverse none"
}
}
)
}
This loop is itself in another loop:
for (let indexChapter = 0; indexChapter < chapters.length; indexChapter++) {
const numChapter = indexChapter + 1;
I've encountered two main problems: either the animations don't trigger, or they trigger at the same time, so by the time I got to the next page, the animation had already begun.
Thank you in advance, my code is not clean, I apologize.