检查元素是否可见
isVisible
函数签名
typescript
function isVisible(element: HTMLElement): boolean描述
检查元素是否可见
参数
| 参数名 | 类型 | 可选 | 默认值 | 描述 |
|---|---|---|---|---|
element | HTMLElement | 否 | - | - |
返回值
boolean
点击查看源码
js
/**
* 检查元素是否可见
* @param element - 要检查的元素
* @returns 元素是否可见
*/
export function isVisible(element) {
if (!element) return false;
const style = getComputedStyle(element);
return (
style.display !== "none" &&
style.visibility !== "hidden" &&
style.opacity !== "0" &&
element.offsetParent !== null
);
}ts
/**
* 检查元素是否可见
* @param element - 要检查的元素
* @returns 元素是否可见
*/
export function isVisible(element: HTMLElement): boolean {
if (!element) return false;
const style = getComputedStyle(element);
return (
style.display !== "none" &&
style.visibility !== "hidden" &&
style.opacity !== "0" &&
element.offsetParent !== null
);
}如有错误,请提交issue :::