Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit b727a6b

Browse files
committed
fix: improve detection of external scroll
'floor' raw scrollPosition when checking for scroll change (codepen returning floating values)
1 parent f069550 commit b727a6b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/scroll.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { AnimationManager } from "./animation-manager"
22
import { EasingFunction, defaultEasingFunction } from "./default-settings"
33
import * as ScrollElement from "./element"
44

5+
const LOW_VALUE = 0.01
6+
57
type ElementOrQuery = Window | Element | string
68
type ScrollOptions = [number?, EasingFunction?]
79

@@ -41,7 +43,9 @@ class Scroll {
4143
this.duration = options.duration || 0
4244
this.easing = options.easing || defaultEasingFunction
4345
this.element.addEventListener("scroll", () => {
44-
const changed = Math.floor(this.animationManager.position) !== this.scrollPosition
46+
const changed =
47+
Math.floor(this.animationManager.position) !== Math.floor(this.scrollPosition) ||
48+
Math.abs(this.animationManager.position - this.scrollPosition) < LOW_VALUE
4549
if (changed) {
4650
this.animationManager.position = this.scrollPosition
4751
}

0 commit comments

Comments
 (0)