Jump to content
Search Community

Snapping on Timeline progress()?

Steve

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Posted

Is there any way to have snapping on Timeline progress()? Snapping to fixed intervals such as .1, .2, .3 of the progress()? 

Thanks for your consideration!

Posted

Before we dive into this ... please explain the desired outcome. I have a feeling there is another way to tackle this.

  • Like 3
Posted

If you still want the animation to play but to pause at certain intervals, tweenTo() is what you're looking for.

 

If you just want to jump to a certain state, you can set the progress: tl.progress(0.1).pause();

 

Past that, we'd need more info like Shaun said :) 

  • Like 2
Posted

I built a Timelinemax Carousel with 11 cards and mapped them to a Jquery UI slider. The next/back functions move .9 of progress() which works fine. The only issue is if the Jquery slider is used and the carousel is not exactly on one of the 11 progress intervals. So I'd like to snap the progress to the 11 progress intervals, .9, .18, .27, etc. Thanks very much for your help.

Posted

I would create labels, have the slider intervals mapped to specific labels, and use tweenTo() to, well, tween to those labels :) 

  • Like 2
Posted

Maybe a minimal demo would be the most helpful in order for us to give proper feedback :) 

  • Like 1
Posted

I figured it out. Here is the function that I put inside the Jquery UI slider object:

 

$("#slider").slider({
      stop: function(event){

      var p = tl.progress();
      var intervals = [0,.9,.18,.27,.36,.45,.54,.63,.72,.81,.9];
      var closest = intervals.reduce(function(prev, curr) {
        return (Math.abs(curr - p) < Math.abs(prev - p) ? curr : prev);
      });

      if ( p != intervals) {
        tl.progress(closest);
      }
      event.stopPropagation();
    }

});

 

Snapping awesome!! Thanks!!

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