joshwnj / joshwnj/react-visibility-sensor

Problem with element that is bigger than viewport

Open
#81 0 comments 4 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
2.3k
Forks
192
PR merge metrics
No merged PRs in 30d

Description

When I have an element that is bigger that the viewport the `onChange` will never trigger with `true`.

That's because we're doing the following check:
```
var visibilityRect = {
top: rect.top >= containmentRect.top,
left: rect.left >= containmentRect.left,
bottom: rect.bottom <= containmentRect.bottom,
right: rect.right <= containmentRect.right
};
```
So in any given moment the `rect.bottom <= containmentRect.bottom && rect.top >= containmentRect.top` will be true.

The solution is to change state to be some kind of enum (`NONE`, `TOP`, `BOTTOM`, `COMPLETE`), so we'll able to trigger `onChange(true)` when `TOP && BOTTOM` exists.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.