Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
microeinhundert

Draggable - Calculate progress to next snap point

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

Hello everyone, i think this is more of a math related question i struggle finding a solution for.

 

I have a slider that is draggable and stops at the different slides with a snap point. Now i want to tween a value from 0 to 1 while between the snap points. I need a way to calculate the progress to the next snap point, that means 0 if at one of the snap points and 1 if 1px in front of the next snap point, then back at 0 and again from the beginning. Is there some math magic ?that can give me this value?

 

Thanks in advance.

 

 

Bildschirmfoto 2019-06-14 um 07.53.27.png

Link to post
Share on other sites

You don't actually want it to be contingent on exactly 1px away, do you? Like...what if it's 0.5px away, what progress (decimal) would you expect? 

 

My guess is that you'd want something like this:

function getProgress(x) {
  return (x % 200) / 200;
}

 

Just feed in an x value and it'll give you a 0-1 progress amount. 

 

Does that help? 

  • Like 1
Link to post
Share on other sites

I‘m going to try it once i‘m back home. But no it  does not need to be exactly 1px, just close enough to not be noticeable in the animation.

Link to post
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.

×