Last active
May 5, 2019 20:14
-
-
Save tarun-dugar/81a591bc8b98005baef55f2338d2f951 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import EASINGS from './easings'; | |
import getScrollTo from './bezier'; | |
const getProgress = ({ | |
easingPreset, | |
cubicBezierPoints, | |
duration, | |
runTime | |
}) => { | |
const percentTimeElapsed = runTime / duration; | |
if (EASINGS.hasOwnProperty(easingPreset)) { | |
return EASINGS[easingPreset](percentTimeElapsed); | |
} else if ( | |
cubicBezierPoints | |
&& !isNaN(cubicBezierPoints.x1) | |
&& !isNaN(cubicBezierPoints.y1) | |
&& !isNaN(cubicBezierPoints.x2) | |
&& !isNaN(cubicBezierPoints.y2) | |
&& cubicBezierPoints.x1 >= 0 | |
&& cubicBezierPoints.x2 >= 0) { | |
return getScrollTo({ | |
percentTimeElapsed, | |
'x1': cubicBezierPoints.x1, | |
'x2': cubicBezierPoints.x2, | |
'y1': cubicBezierPoints.y1, | |
'y2': cubicBezierPoints.y2 | |
}); | |
} else { | |
console.error('Please enter a valid easing value'); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment