使用mootools查找DOM对象是否可见的最佳方法 [英] Best way to find if a DOM object is visible or not, using mootools
本文介绍了使用mootools查找DOM对象是否可见的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
查找DOM对象是否可见的最佳方法是什么?
What is the best way to find if a DOM object is visible?
各种情况下,认为对象不可见:
Various cases when object is considered not visible:
- 显示:无;
- 可见性:隐藏;
- 其中一位父母没有显示:无或可见性:隐藏
- 另一个DOM元素遮住了查询的元素(很不错,但是我可以管理 没有它).
- 屏幕边界之外的项目.
- display: none;
- visibility: hidden;
- one of the parents has display: none or visibility: hidden
- Another DOM element is obscuring the queried element (Nice to have, but I can manage without it).
- Item outside of screen boundaries.
推荐答案
,因为它的mootools已在mootools邮件列表中得到处理,现在它将成为Element.shortcuts的一部分...
since its mootools and this got dealt with on the mootools mail list and it is now going to be a part of 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();
}
});
这篇关于使用mootools查找DOM对象是否可见的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文