1 |
|
2 |
|
3 |
|
4 |
|
5 | const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
|
6 | const { top, left, bottom, right } = el.getBoundingClientRect();
|
7 | const { innerHeight, innerWidth } = window;
|
8 | return partiallyVisible
|
9 | ? ((top > 0 && top < innerHeight) ||
|
10 | (bottom > 0 && bottom < innerHeight)) &&
|
11 | ((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
|
12 | : top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
13 | };
|
14 |
|
15 | export default elementIsVisibleInViewport;
|