Skip to content

Commit 749e2e8

Browse files
committed
fix (ScrollObserver): precent relative to element NaN error
1 parent 3fe1255 commit 749e2e8

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

build/OneLoop.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright 2022 OneLoop.js
44
* Author: Nicolas Langle
55
* Repository: https://github.com/n-langle/OneLoop.js
6-
* Version: 5.1.4
6+
* Version: 5.1.5
77
* SPDX-License-Identifier: MIT
88
*
99
* Credit for easing functions goes to : https://github.com/ai/easings.net/blob/master/src/easings/easingsFunctions.ts
@@ -660,8 +660,6 @@ class ScrollObserverEntry {
660660
Math.min(elementBottom + scrollY - this.startRTE.y, documentScrollSize.y - elementBottom - scrollY + elementHeight, documentScrollSize.y - windowHeight)
661661
);
662662

663-
console.log('distance', this.distanceRTW, this.distanceRTE);
664-
665663
this.control(scrollInfos);
666664

667665
return this
@@ -673,6 +671,10 @@ class ScrollObserverEntry {
673671
p1 = scroll.clone().subtract(this.startRTW).divide(this.distanceRTW),
674672
p2 = scroll.clone().subtract(this.startRTE).divide(this.distanceRTE);
675673

674+
// prevent NaN error
675+
// if scrollX or scrollY is equal to window width or height
676+
p2.set(p2.x || 0, p2.y || 0);
677+
676678
if (p1.x >= 0 && p1.x <= 1 && p1.y >= 0 && p1.y <= 1) {
677679
if (!this._isVisible) {
678680
this._isVisible = true;

0 commit comments

Comments
 (0)