Skip to content

Instantly share code, notes, and snippets.

@tarun-dugar
Last active May 6, 2019 07:48
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/5dcafac0e92ead72106fd60716f094a7 to your computer and use it in GitHub Desktop.
Save tarun-dugar/5dcafac0e92ead72106fd60716f094a7 to your computer and use it in GitHub Desktop.
const B1 = (t) => {
return Math.pow(t, 3);
};
const B2 = (t) => {
return 3 * t * t * (1 - t);
};
const B3 = (t) => {
return 3 * t * Math.pow((1 - t), 2);
};
const B4 = (t) => {
return Math.pow((1 - t), 3);
};
// the cubic bezier function
const getScrollTo = ({ percentTimeElapsed, x1, y1, x2, y2 }) => {
// P0: (0, 0)
// P1: (x1, y1)
// P2: (x2, y2)
// P3: (1, 1)
// return value between 0 and 1 which is the percentage progress
return 1 - (x1 * B1(percentTimeElapsed) + y1 * B2(percentTimeElapsed) + x2 * B3(percentTimeElapsed) + y2 * B4(percentTimeElapsed));
};
export default getScrollTo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment