vanillajs-browser-helpers
Version:
Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser
21 lines (20 loc) • 548 B
JavaScript
import hidden from './hidden';
/**
* Test if a given DOM element is invisible.
*
* @param elm - DOM element to test
* @return Is the element invisible
*/
export default function invisible(elm) {
let checkElm = elm;
while (checkElm && checkElm.tagName !== 'BODY') {
if (hidden(checkElm)
|| !checkElm.offsetHeight
|| !checkElm.offsetWidth
|| !Number(getComputedStyle(checkElm).opacity)) {
return true;
}
checkElm = checkElm.parentElement;
}
return false;
}