15 lines
541 B
TypeScript
15 lines
541 B
TypeScript
import { unref, Ref } from 'vue';
|
|
|
|
export function isHidden(elementRef: HTMLElement | Ref<HTMLElement>) {
|
|
const el = unref(elementRef);
|
|
const style = window.getComputedStyle(el);
|
|
const hidden = style.display === 'none';
|
|
|
|
// offsetParent returns null in the following situations:
|
|
// 1. The element or its parent element has the display property set to none.
|
|
// 2. The element has the position property set to fixed
|
|
const parentHidden = el.offsetParent === null && style.position !== 'fixed';
|
|
|
|
return hidden || parentHidden;
|
|
}
|