Jump to content
Search Community

Snapping on Timeline progress()?

Steve test
Moderator Tag

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

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.

Link to comment
Share on other sites

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

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