Jump to content
GreenSock

MartinSansom

Is there a way to scrub a timeline using a scrollTrigger OR by dragging left and right?

Moderator Tag
Go to solution Solved by Cassie,

Recommended Posts

Hi everyone,

 

I'm trying to create an image sequence that can be played backwards or forwards by scrolling the page up and down. But I also need the sequence to be controllable using a video style progress bar.

 

Using some of the code that I've copied from these forums I've managed to get the image sequence working and I've also managed to create a play bar control with a playhead that can be dragged left and right.

 

But I can't get the playhead to control the current image that is displayed in the image sequence.

 

In the code for the image sequence I specify the number of frames, so I'm assuming I need to divide the length of the progress bar into an equivalent number of 'units' and then advance or rewind the image sequence every time the play head is dragged by one 'unit'. 

See the Pen yLMWwZz by MartinSansom (@MartinSansom) on CodePen

Link to comment
Share on other sites

Will the slider also control scroll position? If not, what happens if the user scrolls after they scrub the slider? If so, maybe try making your slider just control your scroll position.

Link to comment
Share on other sites

Hi,

No, the slider won't control the scroll position, it should just control to the current frame of the animation. But if the user scrolls when the animation is already at the final frame, it should just scroll the page.

 

Thanks

Link to comment
Share on other sites

If it's not possible to have both page scroll and slider controlling the animation, then I'll be more than happy if somebody could help me out with some code to make the slider control the animation.

 

cheers

Link to comment
Share on other sites

  • Solution

You can tie the progress in to values from a range slider like this. 

See the Pen a7fd24fd8d7fd6bfdc25f866bf3c00b5?editors=1011 by cassie-codes (@cassie-codes) on CodePen



Doing both scroll and a slider will definitely be possible but you'll have to work out what to do when the slider and scroll conflict. Which values overwrite which?

  • Like 1
Link to comment
Share on other sites

Will this approach work when there's no tween animations? (I.e. from and to end points)

Link to comment
Share on other sites

Try it out. Every animation has a progress that goes from 0 to 1. It's just a ratio i.e. a percent.

 

  • Like 2
Link to comment
Share on other sites

13 hours ago, Cassie said:

You can tie the progress in to values from a range slider like this. 
 

 


Doing both scroll and a slider will definitely be possible but you'll have to work out what to do when the slider and scroll conflict. Which values overwrite which?

 

 

 

Thank you so so so soooooooo much Cassie - your solution worked perfectly!!!!! (and with so few lines of code, I'm falling back in love with GSAP)

  • Like 1
Link to comment
Share on other sites

You can even animate the progress value for a smoother transition.

slider.addEventListener("input", function () {
  
  gsap.to(tl, {
    progress: slider.value,
    duration: 1,
    ease: "power3"
  });
});

 

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