I am trying to setup multiple gsap scroll triggers with lottie animations in 3 sections. I would like the screen to pin to the animations until they complete. This is the code I currently have, which seems to mostly work. I randomly will see issues where section scroll weird or animations don't finish completely. Any help would be greatly appreciated.
<sectionclass="section--01 section--side-by-side"><divclass="grid-container"><divclass="grid-x grid-padding-x align-center"><divclass="cell medium-6"><h2>Title</h2><p>Description</p></div><divclass="cell medium-6 side-by-side-wrapper"><divid="section-lottie--01"><divclass="lottie-container"></div></div></div></div></div></section><sectionclass="section--02"><divclass="grid-container"><divclass="grid-x grid-padding-x align-center"><divclass="cell small-12 medium-6"><h2class="text-center">Title</h2><divid="section-lottie--02"><divclass="lottie-container"></div></div></div></div></div></section><sectionclass="section--03 section--side-by-side"><divclass="grid-container"><divclass="grid-x grid-padding-x align-center"><divclass="cell medium-6"><h2>Title</h2><p>Text</p></div><divclass="cell medium-6"><h3>Subtitle</h3><divid="section-lottie--03"><divclass="lottie-container"></div></div></div></div></div></section><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.4/gsap.min.js"integrity="sha512-f8mwTB+Bs8a5c46DEm7HQLcJuHMBaH/UFlcgyetMqqkvTcYg4g5VXsYR71b3qC82lZytjNYvBj2pf0VekA9/FQ=="crossorigin="anonymous"referrerpolicy="no-referrer"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.4/ScrollTrigger.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/bodymovin/5.7.8/lottie.min.js"></script><script>
$(document).ready(function(){
let mobile = window.innerWidth <749;
gsap.registerPlugin(ScrollTrigger);LottieScrollTrigger({
target:"#section-lottie--01 .lottie-container",
trigger:".section--01",
path:'/jobseeker-bar-chart.json',
speed:"medium",
pin:".section--01",
scrub:1,
start: mobile ?"center 45%":"center center"});LottieScrollTrigger({
target:"#section-lottie--02 .lottie-container",
trigger:".section--02",
path:'/salary-bar-chart.json',
speed:"medium",
pin:".section--02",
scrub:1,
start:"center 75%"});LottieScrollTrigger({
target:"#section-lottie--03 .lottie-container",
trigger:".section--03",
path:'/salary-scatter-chart.json',
speed:"medium",
pin:".section--03",
scrub:1,
start: mobile ?"center 45%":"center 55%"});functionLottieScrollTrigger(vars){
let playhead ={frame:0},
speeds ={slow:"+=2000", medium:"+=1000", fast:"+=500"},
target = gsap.utils.toArray(vars.target)[0]
st ={trigger: target, pin:true, start:"center center", end: speeds[vars.speed]||"+=1000", scrub:1},
animation = lottie.loadAnimation({
container: target,
renderer: vars.renderer ||"svg",
loop:false,
autoplay:false,
path: vars.path
});for(let p in vars){// let users override the ScrollTrigger defaults
st[p]= vars[p];}
animation.addEventListener("DOMLoaded",function(){
gsap.to(playhead,{
frame: animation.totalFrames -1,
ease:"none",
onUpdate:()=> animation.goToAndStop(playhead.frame,true),
scrollTrigger: st
});});}});</script>
It seems that I get different results when I refresh the page. Randomly the page will jump to the next section while scrolling through an animation.
Multiple scroll triggers for lottie animations in different sections
in GSAP
Posted
I am trying to setup multiple gsap scroll triggers with lottie animations in 3 sections. I would like the screen to pin to the animations until they complete. This is the code I currently have, which seems to mostly work. I randomly will see issues where section scroll weird or animations don't finish completely. Any help would be greatly appreciated.
It seems that I get different results when I refresh the page. Randomly the page will jump to the next section while scrolling through an animation.