Skip to content

Commit bfe1d6d

Browse files
committed
fix: syncTouch tap to stop
1 parent f024b96 commit bfe1d6d

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

packages/core/src/lenis.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,13 @@ export class Lenis {
274274
// return
275275
// }
276276

277+
const isClickOrTap = deltaX === 0 && deltaY === 0
278+
277279
const isTapToStop =
278280
this.options.syncTouch &&
279281
isTouch &&
280282
event.type === 'touchstart' &&
283+
isClickOrTap &&
281284
!this.isStopped &&
282285
!this.isLocked
283286

@@ -286,8 +289,6 @@ export class Lenis {
286289
return
287290
}
288291

289-
const isClick = deltaX === 0 && deltaY === 0 // click event
290-
291292
// const isPullToRefresh =
292293
// this.options.gestureOrientation === 'vertical' &&
293294
// this.scroll === 0 &&
@@ -298,7 +299,7 @@ export class Lenis {
298299
(this.options.gestureOrientation === 'vertical' && deltaY === 0) ||
299300
(this.options.gestureOrientation === 'horizontal' && deltaX === 0)
300301

301-
if (isClick || isUnknownGesture) {
302+
if (isClickOrTap || isUnknownGesture) {
302303
// console.log('prevent')
303304
return
304305
}
@@ -360,7 +361,7 @@ export class Lenis {
360361

361362
event.preventDefault()
362363

363-
const syncTouch = isTouch && this.options.syncTouch
364+
const isSyncTouch = isTouch && this.options.syncTouch
364365
const isTouchEnd = isTouch && event.type === 'touchend'
365366

366367
const hasTouchInertia = isTouchEnd && Math.abs(delta) > 5
@@ -371,9 +372,10 @@ export class Lenis {
371372

372373
this.scrollTo(this.targetScroll + delta, {
373374
programmatic: false,
374-
...(syncTouch
375+
...(isSyncTouch
375376
? {
376377
lerp: hasTouchInertia ? this.options.syncTouchLerp : 1,
378+
// immediate: !hasTouchInertia,
377379
}
378380
: {
379381
lerp: this.options.lerp,

playground/core/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ document
1212

1313
const lenis = new Lenis({
1414
autoRaf: true,
15+
syncTouch: true,
1516
// autoResize: false,
1617
// lerp: 0.9,
1718
// virtualScroll: (e) => {

playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "module",
44
"version": "0.0.1",
55
"scripts": {
6-
"dev": "astro dev",
6+
"dev": "astro dev --host",
77
"start": "astro dev",
88
"build": "astro check && astro build",
99
"preview": "astro preview",

0 commit comments

Comments
 (0)