Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace defaultLenisOptions object with function #534

Open
wants to merge 1 commit into
base: v5-beta
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ import {
lenisTargetScrollTo,
} from './types';

/**
* @type {ILenisOptions}
*/
const defaultLenisOptions: ILenisOptions = {
wrapper: window,
content: document.documentElement,
eventsTarget: window,
lerp: 0.1,
duration: 0.75,
orientation: 'vertical',
gestureOrientation: 'vertical',
smoothWheel: true,
smoothTouch: false,
syncTouch: false,
syncTouchLerp: 0.1,
touchInertiaMultiplier: 35,
wheelMultiplier: 1,
touchMultiplier: 2,
normalizeWheel: false,
autoResize: true,
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou
};

function getDefaultLenisOptions(): ILenisOptions {
return {
wrapper: window,
content: document.documentElement,
eventsTarget: window,
lerp: 0.1,
duration: 0.75,
orientation: 'vertical',
gestureOrientation: 'vertical',
smoothWheel: true,
smoothTouch: false,
syncTouch: false,
syncTouchLerp: 0.1,
touchInertiaMultiplier: 35,
wheelMultiplier: 1,
touchMultiplier: 2,
normalizeWheel: false,
autoResize: true,
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou
}
}

/**
* Locomotive Scroll
Expand Down Expand Up @@ -78,7 +78,7 @@ export default class LocomotiveScroll {
destroyCustomTicker,
}: ILocomotiveScrollOptions = {}) {
// Arguments
this.lenisOptions = { ...defaultLenisOptions, ...lenisOptions };
this.lenisOptions = { ...getDefaultLenisOptions(), ...lenisOptions };

Object.assign(this, {
lenisOptions,
Expand Down Expand Up @@ -290,7 +290,7 @@ export default class LocomotiveScroll {
const duration =
$target.getAttribute('data-scroll-to-duration') ||
this.lenisOptions.duration ||
defaultLenisOptions.duration;
getDefaultLenisOptions().duration;

target &&
this.scrollTo(target, {
Expand Down