Jump to content
Search Community

Control video with ScrollTrigger inside SPA

Josu test
Moderator Tag

Recommended Posts

Hi!


I've spent two days researching for this with no luck.

 

I'm developing a SPA which contains video in between and wanted to control its advance with the scroll.

 

Something like this: https://codepen.io/melo07/pen/Jjozjgw 

 

But like in this example I have only found examples where the page is only the video.

 

If I put some other content before or after it stops working.

 

Please, someone have any example or guidance for something like this?

 

Thank you in advance.

 

See the Pen Jjozjgw  by melo07 (@melo07) on CodePen

Link to comment
Share on other sites

Hi!

In first place I've tried pin the video but it went wrong.

The video goes inside a "pin-spacer" container which gets extra height and breaks the layout.
Without the pin the video is in position but the scroll works normal and keep going down.

 

I've updated the codepen now with some code I've been trying but it's not working.

 

Link to comment
Share on other sites

Hi again and thank for not just let this go.

 

By now I've achieved to play the video onEnter, stop it onLeave and play it from beginning onEnterBack (codepen updated so far).

 

But still need to control the video through the scroll.
Is there some method which gives me the current timeline advance?
I've tried progress but no with no luck, probably by my fault.

I'm thinking about keeping trace of page scroll in order to compare it with current timeline progress so I could set video.currentTime or maybe something like that...

 

 

"onloadeddata" works as event listener in order to avoid errors caused by the video isn't still available.

 

  • Like 1
Link to comment
Share on other sites

Hi again!

 

Yes, Mikel, that's pretty much what I was looking for!!

THANK YOU!!

 

May I ask you about this line:

frameNumber = self.progress/10*150;

 

What's the reason for that values (10 and 150)?

And how do you adjust it after different video lengths?

 

Thank you again!!

And, of course, thank you too, Cassie!!

 

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