Move easings into global file
This commit is contained in:
15
src/animations/easings.ts
Normal file
15
src/animations/easings.ts
Normal file
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user