From 9e7252d65ac7b1b03ba8f2fe4884803ee727a4d8 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski <daniel.kurowski@grifart.cz> Date: Fri, 29 May 2020 16:49:04 +0200 Subject: [PATCH] Extracted custom easing name into constant --- src/scrollToTarget.ts | 3 ++- src/setupVelocity.d.ts | 1 + src/setupVelocity.js | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/scrollToTarget.ts b/src/scrollToTarget.ts index 0a5c714..598766f 100644 --- a/src/scrollToTarget.ts +++ b/src/scrollToTarget.ts @@ -1,11 +1,12 @@ import * as Velocity from 'velocity-animate'; import {HashTarget} from './HashTarget'; +import {EASE_IN_SKIP_OUT_EASING} from './setupVelocity'; export function scrollToTarget(hashTarget: HashTarget): void { Velocity.animate(hashTarget.getElement(), 'scroll', { duration: 1200, // todo: different depending on offset from page top? - easing: 'ease-in-skip-out', + easing: EASE_IN_SKIP_OUT_EASING, complete: () => window.location.hash = hashTarget.getHash(), }); } diff --git a/src/setupVelocity.d.ts b/src/setupVelocity.d.ts index 09599dc..7f66e6b 100644 --- a/src/setupVelocity.d.ts +++ b/src/setupVelocity.d.ts @@ -1,4 +1,5 @@ import * as Velocity from 'velocity-animate'; declare const setupVelocity: (velocity: typeof Velocity) => void; +export declare const EASE_IN_SKIP_OUT_EASING: string; export default setupVelocity; diff --git a/src/setupVelocity.js b/src/setupVelocity.js index a58f372..4d0264e 100644 --- a/src/setupVelocity.js +++ b/src/setupVelocity.js @@ -1,3 +1,5 @@ +export const EASE_IN_SKIP_OUT_EASING = 'ease-in-skip-out'; + // e.g. (5, 5, 10, 500, 1000) => 500 // e.g. (5, 0, 10, 500, 1000) => 750 const mapIntervalLinear = (number, originalFrom, originalTo, newFrom, newTo) => { @@ -67,7 +69,7 @@ const computeHowMuchToSkip = (tweenDelta) => { }; const setupVelocity = (velocity) => { - velocity.Easings['ease-in-skip-out'] = composeEasing( + velocity.Easings[EASE_IN_SKIP_OUT_EASING] = composeEasing( (time, opts, tweenDelta) => mapIntervalLinear( velocity.Easings['ease-in'](time, opts, tweenDelta), 0, 1, // from interval -- GitLab