Jump to content
Search Community

How to Reduce the speed of GSAP scroll animation.

ej2 test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

const drawImage = useCallback(() => {
    const image = images[defaultFrame.frame];
    const canvas = document.querySelector("canvas") as HTMLCanvasElement;
    // window.innerWidth
    canvas.style.width = `${width}`;
    // window.innerHeight
    canvas.style.height = `${height}`;

    const context = canvas.getContext("2d") as CanvasRenderingContext2D;
  
    // window.innerWidth
    context.canvas.width = width;
    // window.innerHeight
    context.canvas.height = height;

    context.clearRect(0, 0, canvas.width, canvas.height);

    // Draw the image on the canvas
    //, width, height
    context.drawImage(image, 0, 0, canvas.width, canvas.height);
  }, [defaultFrame.frame, height, images, width]);

  const initGSAP = useCallback(() => {
    gsap.to(defaultFrame, {
      frame: frameCount - 1,
      snap: "frame",
      ease: "none",
      scrollTrigger: {
        scrub: true,
        pin: "canvas",
      },
      onUpdate: drawImage,
    });
    gsap.fromTo(
      ".game",
      {
        opacity: 0.1,
      },
      {
        opacity: 1,
        scrollTrigger: {
          scrub: true,
          start: "0%",
          end: "100%",
        },
        onComplete: () => {
          // do stuff
        },
      }
    );
    images[defaultFrame.frame].onload = drawImage;
  }, [defaultFrame, drawImage, images]);

I want to reduce the speed of my gsap image animation on scroll, please how can I achieve this?

Here a video
 

Link to comment
Share on other sites

  • ej2 changed the title to How to Reduce the speed of GSAP scroll animation.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...