Hi momo!
Here is an example if you want animate your lines when they are on screen... I have not tested, but I think it's good!
let gsplit;
$(window).on('load', function(){
/*
* Register GSAP Plugins
*/
gsap.registerPlugin(ScrollTrigger, SplitText);
/*
* Init SplitText Gsap Plugin
*/
gsplit = new SplitText('.splitText', {
type: 'chars,words,lines',
charsClass: 'char',
linesClass: 'line',
wordsClass: 'word'
});
// Prevent Bug, add opacity 0 to your CSS and turn it to opacity 1 when ready.
$('.splitText').css({opacity: 1});
/*
* With ScrollTrigger, on Scroll, reveal each line of a pragraph when is coming in viewport
*/
const paragraphs_lines = gsap.utils.toArray('.to-reveal .line');
// Add translateY -10 and opacity 0 for the test to your CSS on elements ".to-reveal .line"
paragraphs_lines.forEach((line, i, v) => {
gsap.to(line, {
y: 0,
opacity: 1,
stagger: .03,
scrollTrigger: {
trigger: line,
start: 'top ' + (window.innerHeight - 100), // Bottom position - 100px
end: 'bottom ' + (window.innerHeight - 100), // Bottom position - 100px
scrub: true,
markers: true
}
});
});
});
You can turn scrub parameter to false or just not add it if you when a reveal based on the viewport only and not on scroll + viewport.
EDIT: Maybe you don't want anim your paragraph based on scroll/viewport position, but directly, with delay or not... Just remove scrollTrigger and add a delay or not.... I push a repair in my code too. Change splitText variable to gsplit.
Best Regards!
Sam