<分区>
查找 DOM 对象是否可见的最佳方法是什么?
对象被认为不可见的各种情况:
- 显示:无;
- 可见性:隐藏;
- parent 之一有 display: none 或 visibility: hidden
- 另一个 DOM 元素遮盖了被查询的元素(很高兴,但我可以管理 没有它)。
- 项目超出屏幕边界。
<分区>
查找 DOM 对象是否可见的最佳方法是什么?
对象被认为不可见的各种情况:
最佳答案
因为它的 mootools 和 this 在 mootools 邮件列表上得到了处理,它现在将成为 Element.shortcuts 的一部分...
/*
* Inspired from http://github.com/jeresig/sizzle/commit/7631f9c3f85e5fa72ac51532399cb593c2cdc71f
* and this http://github.com/jeresig/sizzle/commit/5716360040a440041da19823964f96d025ca734b
* and then http://dev.jquery.com/ticket/4512
*/
Element.implement({
isHidden: function(){
var w = this.offsetWidth, h = this.offsetHeight,
force = (this.tagName === 'TR');
return (w===0 && h===0 && !force) ? true : (w!==0 && h!==0 && !force) ? false : this.getStyle('display') === 'none';
},
isVisible: function(){
return !this.isHidden();
}
});
关于javascript - 使用 mootools 查找 DOM 对象是否可见的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1056357/