From e426e6693b8959aec5d0474ddc5354f3a69408eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Roche?= Date: Mon, 25 Nov 2024 13:00:10 +0100 Subject: [PATCH] fix lenis-scrolling css class --- packages/core/src/lenis.ts | 15 +++++++++------ playground/core/style.css | 5 +++++ playground/core/test.ts | 12 ++++++++++++ playground/www/pages/core.astro | 6 +++++- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/packages/core/src/lenis.ts b/packages/core/src/lenis.ts index 0b12fecc..8c98fae1 100644 --- a/packages/core/src/lenis.ts +++ b/packages/core/src/lenis.ts @@ -415,7 +415,11 @@ export class Lenis { this.direction = Math.sign( this.animatedScroll - lastScroll ) as Lenis['direction'] - this.isScrolling = 'native' + + if (!this.isStopped) { + this.isScrolling = 'native' + } + this.emit() if (this.velocity !== 0) { @@ -442,9 +446,9 @@ export class Lenis { */ start() { if (!this.isStopped) return - this.isStopped = false - this.reset() + + this.isStopped = false } /** @@ -452,10 +456,9 @@ export class Lenis { */ stop() { if (this.isStopped) return - this.isStopped = true - this.animate.stop() - this.reset() + + this.isStopped = true } /** diff --git a/playground/core/style.css b/playground/core/style.css index 3b315493..12d04020 100644 --- a/playground/core/style.css +++ b/playground/core/style.css @@ -19,3 +19,8 @@ width: 100vw; } */ } + +#debug { + position: sticky; + top: 4rem; +} diff --git a/playground/core/test.ts b/playground/core/test.ts index 3efef3b6..dd42b297 100644 --- a/playground/core/test.ts +++ b/playground/core/test.ts @@ -96,3 +96,15 @@ document.documentElement.addEventListener('wheel', (e) => { // } // requestAnimationFrame(raf) + +const stopButton = document.getElementById('stop') +const startButton = document.getElementById('start') + +stopButton?.addEventListener('click', () => { + lenis.stop() + console.log('stop') +}) + +startButton?.addEventListener('click', () => { + lenis.start() +}) diff --git a/playground/www/pages/core.astro b/playground/www/pages/core.astro index 17d779c0..baff4c73 100644 --- a/playground/www/pages/core.astro +++ b/playground/www/pages/core.astro @@ -3,7 +3,11 @@ import '~/core/style.css' import Layout from '../layouts/Layout.astro' --- - +
+ + + +