Share Posted June 14, 2019 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. Link to comment Share on other sites More sharing options...
Share Posted June 14, 2019 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? 1 Link to comment Share on other sites More sharing options...
Author Share Posted June 14, 2019 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 comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now