Jump to content
Search Community

Clamp scrollTrigger progress value

frederik222 test
Moderator Tag

Recommended Posts

Hi there,

 

I'm using scrollTrigger  `onUpdate` method which gives access to `progress` and this indicates the `start` and the `end` value which are  the range`0` between `1` , I have tried to clamp those values to get like `0` and `2.8` but this is not working 
 

 function clamp(num, min, max) {
   return num <= min ? min : num >= max ? max : num;
 }

 

 

 

I'm trying to use scrollTrigger with video 

onUpdate(evt) {

   videoScrollNode.currentTime = evt.progress

}

 

the video length is 00:28 , any idea how can i achieve this

 

Thanks for the help.

Link to comment
Share on other sites

Hey Frederik and welcome to the GreenSock forums.

 

As Jack said you could use mapRange. However since the progress values is always between 0 and 1 you could just multiply by the max time of your video:

let videoDuration;
videoScrollNode.addEventListener('loadedmetadata', e => {
  videoDuration = console.log(videoScrollNode.duration);
});

// In the ScrollTrigger:
onUpdate: ({progress}) => {
   videoScrollNode.currentTime = videoDuration * progress;
}

 

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