Hey, im trying to do a scroll animation thats swaps images as you scroll, my problem is that the animation "shake" while scrolling, this only happens the first couple of times you scroll, but it is not a loading problem i think since if i let it load for a couple of mins it still is shaky. Also once you scroll all the way down, the last frame kinda reset. Any idea what i could do?
https://cargoweb.netlify.app/#/home (the first animation)
const tl = gsap.timeline({
scrollTrigger: {
trigger: container,
scrub: 1,
start: "top top",
end: "200%",
pin: true,
pinType: "transform",
anticipatePin: 1,
}
});
// canvas resize handler
window.addEventListener('resize', function resize() {
ctx.canvas.width = document.documentElement.clientWidth;
ctx.canvas.height = document.documentElement.clientHeight;
return resize;
}());
// when all images ready
images.then((imgs) => {
this.onReady.emit(true);
const counter = {i: 0}; // iteration object
tl.to(counter, {
i: imgs.length - 1, // increment counter to frames length
roundProps: "i", // round, only int
ease: "none", // ease provided by smooth-scroll momentum
immediateRender: true, // render first frame immediately
onUpdate: () => this.calcDrawImage(ctx, imgs[counter.i]) // draw image in canvas when timeline update
}, 0);
// draw current frame again when scroll stopped and resize happened
window.addEventListener('resize', () => this.calcDrawImage(ctx, imgs[counter.i]));
});