迭代判断本身及祖先元素是否可见

/**
* 判断元素是否可见
* @param el{dom}: dom元素
* @eg: isVisible(document.querySelector(cssSelector));
**/
function isVisible(el) {
    var loopable = true,
        visible = getComputedStyle(el).display != 'none' && getComputedStyle(el).visibility != 'hidden';
        
    while(loopable && visible) {
        el = el.parentNode;
        
        if(el && el != document.body) {
            visible = getComputedStyle(el).display != 'none' && getComputedStyle(el).visibility != 'hidden';
        }else {
            loopable = false;
        }
    }
    
    return visible;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
  • 2022-12-23
  • 2021-05-16
猜你喜欢
  • 2021-06-02
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-05
  • 2022-02-20
  • 2022-01-29
相关资源
相似解决方案