From 8524a83199fdf68894f9c3b769968814d3b3eaf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Sat, 13 Aug 2022 23:38:59 +0200 Subject: [PATCH] Move easings into global file --- src/animations/easings.ts | 15 +++++++++++++++ src/utils/functions/easing.ts | 9 --------- src/utils/functions/index.ts | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 src/animations/easings.ts delete mode 100644 src/utils/functions/easing.ts diff --git a/src/animations/easings.ts b/src/animations/easings.ts new file mode 100644 index 0000000..e9321fe --- /dev/null +++ b/src/animations/easings.ts @@ -0,0 +1,15 @@ +/** + * Ease: Quart Out Array + */ +export const quartOut = [.165, .84, .44, 1] + + +/** + * Ease: Quart In Out function + */ +export const quartInOutFunc = (t: number, b: number, c: number, d: number) => { + t /= d/2 + if (t < 1) return c/2 * t * t * t * t + b + t -= 2 + return -c / 2 * (t * t * t * t - 2) + b +} \ No newline at end of file diff --git a/src/utils/functions/easing.ts b/src/utils/functions/easing.ts deleted file mode 100644 index 270971c..0000000 --- a/src/utils/functions/easing.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Ease: In Out Quart - */ -export const easeInOutQuart = (t: number, b: number, c: number, d: number) => { - t /= d/2 - if (t < 1) return c/2 * t * t * t * t + b - t -= 2 - return -c / 2 * (t * t * t * t - 2) + b -} \ No newline at end of file diff --git a/src/utils/functions/index.ts b/src/utils/functions/index.ts index 057e99b..406ef92 100644 --- a/src/utils/functions/index.ts +++ b/src/utils/functions/index.ts @@ -176,7 +176,7 @@ const smoothScrollPromise = (target: HTMLElement, duration: number = 1600): Prom if (startTime === null) startTime = currentTime const timeElapsed = currentTime - startTime // Create easing value - const easedYPosition = easeInOutQuart(timeElapsed, startPosition, distance, duration) + const easedYPosition = quartInOutFunc(timeElapsed, startPosition, distance, duration) // Scroll to Y position window.scrollTo(0, easedYPosition) // Loop or end animation