main
| 1 | export default function checkElementInViewport( |
| 2 | element: Element, |
| 3 | percentage = 100 |
| 4 | ) { |
| 5 | const rect = element.getBoundingClientRect() |
| 6 | const windowHeight: number | undefined = |
| 7 | window.innerHeight || document.documentElement.clientHeight |
| 8 | |
| 9 | return !( |
| 10 | Math.floor(100 - ((rect.top >= 0 ? 0 : rect.top) / +-rect.height) * 100) < |
| 11 | percentage || |
| 12 | Math.floor(100 - ((rect.bottom - windowHeight) / rect.height) * 100) < |
| 13 | percentage |
| 14 | ) |
| 15 | } |