Skip to content
Snippets Groups Projects
Commit 9e7252d6 authored by Daniel Kurowski's avatar Daniel Kurowski
Browse files

Extracted custom easing name into constant

parent d63b0401
Branches
Tags
1 merge request!7Improve structure
Pipeline #26887 passed
import * as Velocity from 'velocity-animate'; import * as Velocity from 'velocity-animate';
import {HashTarget} from './HashTarget'; import {HashTarget} from './HashTarget';
import {EASE_IN_SKIP_OUT_EASING} from './setupVelocity';
export function scrollToTarget(hashTarget: HashTarget): void export function scrollToTarget(hashTarget: HashTarget): void
{ {
Velocity.animate(hashTarget.getElement(), 'scroll', { Velocity.animate(hashTarget.getElement(), 'scroll', {
duration: 1200, // todo: different depending on offset from page top? 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(), complete: () => window.location.hash = hashTarget.getHash(),
}); });
} }
import * as Velocity from 'velocity-animate'; import * as Velocity from 'velocity-animate';
declare const setupVelocity: (velocity: typeof Velocity) => void; declare const setupVelocity: (velocity: typeof Velocity) => void;
export declare const EASE_IN_SKIP_OUT_EASING: string;
export default setupVelocity; export default setupVelocity;
export const EASE_IN_SKIP_OUT_EASING = 'ease-in-skip-out';
// e.g. (5, 5, 10, 500, 1000) => 500 // e.g. (5, 5, 10, 500, 1000) => 500
// e.g. (5, 0, 10, 500, 1000) => 750 // e.g. (5, 0, 10, 500, 1000) => 750
const mapIntervalLinear = (number, originalFrom, originalTo, newFrom, newTo) => { const mapIntervalLinear = (number, originalFrom, originalTo, newFrom, newTo) => {
...@@ -67,7 +69,7 @@ const computeHowMuchToSkip = (tweenDelta) => { ...@@ -67,7 +69,7 @@ const computeHowMuchToSkip = (tweenDelta) => {
}; };
const setupVelocity = (velocity) => { const setupVelocity = (velocity) => {
velocity.Easings['ease-in-skip-out'] = composeEasing( velocity.Easings[EASE_IN_SKIP_OUT_EASING] = composeEasing(
(time, opts, tweenDelta) => mapIntervalLinear( (time, opts, tweenDelta) => mapIntervalLinear(
velocity.Easings['ease-in'](time, opts, tweenDelta), velocity.Easings['ease-in'](time, opts, tweenDelta),
0, 1, // from interval 0, 1, // from interval
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment