刚刚在看echo.js的源码,因此此问题延伸自echo.js中的一行代码chrome
var isHidden = function(element) { return (element.offsetParent === null); };
通过本身实践确实能够使用这种方法来判断当前元素是否被隐藏,包括经过设置父元素为display:none
以及本身自己为none
的状况。可是若是是经过设置visibility:hidden
则没法检测出。dom
overflow关于这个问题的讨论优化
除了上面的方法还有这种element
function isHidden(el) { var style = window.getComputedStyle(el); return (style.display === 'none') }
这种方式也是须要手动判断visibility
。不过貌似offsetParent
的方法十分缓慢,即便是新的chrome也没法优化。get