Hey!
I only recently started experimenting with gsap and so far i really love it.
I'm making a website with scrolltrigger animations, basically a svg path that is 100% height and width with position fixed and it's being animated on scroll (background effect). I have 4 sections and each section will trigger a transition animation.
On initial page load, the animation plays out well. But, If I refresh the page somewhere in the middle it will sometime load correctly and other times it will mess up positioning (instead of going 200px right it goes completely off screen).
Any idea what could be the issue? Am I not using scroll trigger correctly?
//SVG's path that's being animated
<svg
height="100%"
width="100%"
viewBox="0 0 1000 700"
preserveAspectRatio="none"
class="{className} {blobClass}"
>
<path height="100%" width="100%" d="" fill="#eff0fd" />
</svg>
//Callback to function that loops a svg animation
let tl = gsap.timeline({
onUpdate: function () {
animate();
},
repeat: -1
});
//animate transition to section 2
let blobTl02 = gsap.timeline({
scrollTrigger: {
trigger: '.section-02',
start: 'top bottom',
scrub: 1.5,
end: 'bottom bottom'
// markers: true
},
onComplete: function () {
tl.pause();
},
onReverseComplete: function () {
tl.play();
}
});
blobTl02.set(`.${blobClass} path`, { transformOrigin: 'center center' });
blobTl02.to(
`.${blobClass} path`,
{
// scale: '5',
// translateX: '-200px',
translateY: '-350px',
ease: 'Power1.inOut'
},
'transition'
);
blobTl02.to(
`.${blobClass} path`,
{
scale: '6.5',
fill: '#faf9ff',
ease: 'Power1.inOut',
delay: '0.1'
},
'transition'
);
//Animate to section 3
let blobTl03 = gsap.timeline({
scrollTrigger: {
trigger: '.section-03',
start: 'top bottom',
scrub: 1.5,
end: 'bottom bottom'
// markers: true
},
onComplete: function () {
tl.play();
},
onReverseComplete: function () {
tl.pause();
}
});
blobTl03
.to(
`.${blobClass} path`,
{
// scale: '5',
// translateX: '-200px',
translateY: 50,
translateX: -430,
ease: 'Power1.inOut'
},
'transition'
)
.to(
`.${blobClass} path`,
{
scale: 1,
fill: '#faf9ff',
ease: 'Power1.inOut',
delay: '0.1'
},
'transition'
);
//Animate to section 4
let blobTl04 = gsap.timeline({
scrollTrigger: {
trigger: '.section-04',
start: 'top bottom',
scrub: 1.5,
end: 'bottom bottom'
// markers: true
},
onComplete: function () {
tl.pause();
},
onReverseComplete: function () {
tl.play();
}
});
blobTl04
.to(
`.${blobClass} path`,
{
scale: 5.5,
fill: '#faf9ff',
ease: 'Power1.inOut',
delay: '0.1'
},
'transition'
);