Skip to content

Commit

Permalink
Gregt/negative viewable threshold (#28)
Browse files Browse the repository at this point in the history
* Can work with negative viewability threshold.

* Offset in log remark is now VT for clarity.

* Checking for isNaN

* removed logging

Co-authored-by: Engywook2005 <greg.thorson@apartmenttherapy.com>
  • Loading branch information
Engywook2005 and Engywook2005 authored May 16, 2022
1 parent c509747 commit d41c2be
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Bling.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/isInViewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit d41c2be

Please sign in to comment.