13 lines
326 B
TypeScript
13 lines
326 B
TypeScript
import windowSize from './windowSize';
|
|
|
|
export function isElementInViewport(el: HTMLElement) {
|
|
if (el.style.display === 'none') {
|
|
return false;
|
|
}
|
|
|
|
const rect = el.getBoundingClientRect();
|
|
const { height: windowHeight } = windowSize.get();
|
|
|
|
return (rect.top <= windowHeight) && ((rect.top + rect.height) >= 0);
|
|
}
|