I'm playing around with some simple GSAP animations and I'm noticing that there is an issue with them running smoothly on a mobile browser(Brave and Chrome Android). For example the following code looks perfect on desktop devices while on mobile the animations seem to lag.
<div class="container" id="contentContainer">
<div class="content-start">
<div class="medium-box box-1">
The Mekong river originates in the Himalayas in China, where it is known as the Lancang. It flows through the Lower Mekong Basin countries of Myanmar, Laos, Thailand, Cambodia and Vietnam, where it reaches the South China Sea.
</div>
</div>
</div>
let mySplitText = new SplitText('.box-1', { type: "words,chars" }),
chars = mySplitText.chars; //an array of all the divs that wrap each character
gsap.fromTo('.box-1',{y: '100%', opacity: 0},{y: 0, opacity: 1, duration: 1, scrollTrigger: {
trigger: '.box-1',
start: 'top 60%',
end: "bottom 50%",
pin: true,
pinSpacing: false,
markers: true,
onEnter: () => {
gsap.to('.box-1',{duration: 1, y: '0', opacity: 1})
gsap.from(chars, {duration: 0.5,opacity: 1,scale: 0,ease: "back",stagger: 0.01})
},
onLeave: () => {
gsap.to('.box-1',{duration: 1, y: '-100%', opacity: 0})
},
onEnterBack: () => {
gsap.to('.box-1',{duration: 1, y: 0, opacity: 1})
gsap.from(chars, {duration: 0.5, opacity: 1,scale: 0,ease: "back",stagger: 0.01})
},
onLeaveBack: () => {
gsap.to('.box-1',{duration: 1, y: '100%', opacity: 0})
}
}})
I think one of the reasons the animation lags is because of the navigation bar on mobile devices that pops up when scrolling down, resizing the viewport, and changing the start and end triggers.
I also realize since I'm quite new that my code might not be very efficient and that might impact performance.
I would appreciate any tips as to how to make this scrolling experience smooth for all users on all devices.Thanks in advance.