From d41c2bee481ba2601db9111838a4eaf7e8f1f9ad Mon Sep 17 00:00:00 2001 From: Greg Thorson Date: Mon, 16 May 2022 16:14:49 -0400 Subject: [PATCH] Gregt/negative viewable threshold (#28) * Can work with negative viewability threshold. * Offset in log remark is now VT for clarity. * Checking for isNaN * removed logging Co-authored-by: Engywook2005 --- src/Bling.js | 2 +- src/utils/isInViewport.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Bling.js b/src/Bling.js index 45975a2..f4e5d5a 100644 --- a/src/Bling.js +++ b/src/Bling.js @@ -389,7 +389,7 @@ class Bling extends Component { } get viewableThreshold() { - return this.props.viewableThreshold >= 0 + return !isNaN(this.props.viewableThreshold) ? this.props.viewableThreshold : Bling._config.viewableThreshold; } diff --git a/src/utils/isInViewport.js b/src/utils/isInViewport.js index 28e50b0..60e9c7b 100644 --- a/src/utils/isInViewport.js +++ b/src/utils/isInViewport.js @@ -15,10 +15,12 @@ export default function isInViewport(el, [width, height] = [0, 0], offset = 0) { bottom: window.innerHeight, right: window.innerWidth }; + const inViewport = rect.bottom >= viewport.top + height * offset && rect.right >= viewport.left + width * offset && rect.top <= viewport.bottom - height * offset && rect.left <= viewport.right - width * offset; + return inViewport; }