Skip to content

Instantly share code, notes, and snippets.

@tarun-dugar
Last active May 5, 2019 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarun-dugar/81a591bc8b98005baef55f2338d2f951 to your computer and use it in GitHub Desktop.
Save tarun-dugar/81a591bc8b98005baef55f2338d2f951 to your computer and use it in GitHub Desktop.
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