From b727a6b7cf3dab878930b7f66952a3cf5c0a845b Mon Sep 17 00:00:00 2001 From: David Perez Alvarez Date: Sun, 5 May 2019 23:23:03 -0400 Subject: [PATCH] fix: improve detection of external scroll 'floor' raw scrollPosition when checking for scroll change (codepen returning floating values) --- src/scroll.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/scroll.ts b/src/scroll.ts index c4e279d..c3b0e08 100644 --- a/src/scroll.ts +++ b/src/scroll.ts @@ -2,6 +2,8 @@ import { AnimationManager } from "./animation-manager" import { EasingFunction, defaultEasingFunction } from "./default-settings" import * as ScrollElement from "./element" +const LOW_VALUE = 0.01 + type ElementOrQuery = Window | Element | string type ScrollOptions = [number?, EasingFunction?] @@ -41,7 +43,9 @@ class Scroll { this.duration = options.duration || 0 this.easing = options.easing || defaultEasingFunction this.element.addEventListener("scroll", () => { - const changed = Math.floor(this.animationManager.position) !== this.scrollPosition + const changed = + Math.floor(this.animationManager.position) !== Math.floor(this.scrollPosition) || + Math.abs(this.animationManager.position - this.scrollPosition) < LOW_VALUE if (changed) { this.animationManager.position = this.scrollPosition }