原生js判断元素是否可见
迭代判断本身及祖先元素是否可见
/**
* 判断元素是否可见
* @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;
}