Jump to content
Search Community

Fix video until finishes

luda test
Moderator Tag

Recommended Posts

Hi! Previously I asked how to play a video depending on the scroll and I already achieve that. 

Now I have been trying to fix the container video on the 100vh until the video finishes. Here I show a video of how my actual project works.

 

https://drive.google.com/file/d/11VPRgnHDnNvbSBtCdrrXMg4pgutD5zqg/view?usp=sharing

 

The solution that I want only works only when I scroll backward. When I scroll from top to bottom and the markers cross each other, the container disappears. And also the container joins the one below

 

I also recreate the project in the Stackbitz link

https://stackblitz.com/edit/react-ymjgyj?file=src/App.js

 

Link to comment
Share on other sites

Hi,

 

You're not using GSAP Context, so you are officially another victim of React's Strict Mode double effect call ;)

https://greensock.com/docs/v3/GSAP/gsap.context()

 

This seems to work the way you intend:

useLayoutEffect(() => {
  const ctx = gsap.context(() => {
    let tl = gsap.timeline({
      scrollTrigger: {
        trigger: container.current,
        start: 'top top',
        end: 'bottom top',
        scrub: true,
        markers: true,
        pin: container.current,
        pinSpacing: false,
      },
    });

    video.current.onloadedmetadata = function () {
      tl.to(video.current, { currentTime: video.current.duration });
    };
  });
  return () => ctx.revert();
}, []);

You can read more about it here:

 

Hopefully this helps.

Happy Tweening!

  • Thanks 1
  • Haha 1
Link to comment
Share on other sites

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...