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

Commit

Permalink
fix: improve detection of external scroll
Browse files Browse the repository at this point in the history
'floor' raw scrollPosition when checking for scroll change (codepen returning floating values)
  • Loading branch information
davidpa9708 committed May 6, 2019
1 parent f069550 commit b727a6b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?]

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b727a6b

Please sign in to comment.