Firefox,查询选择器和可见伪选择器 [英] Firefox, query selector and the visible pseudo selector

查看:211
本文介绍了Firefox,查询选择器和可见伪选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何,在Firefox的querySelector()或querySelectorAll()函数中使用伪选择器来检测可见性?特别是我想能够做到这样的事情:

  elem.querySelector('#list .list-item:visible ); 
elem.querySelector('#section .sub-section:visible .title');

不需要担心浏览器不一致或其他的实现,只是Firefox。感谢!



编辑显示不是 none strong> visibility 不是 hidden

解决方案

CSS规范没有定义:visible code>(或相关的)选择器,而且AFAIK Firefox不会执行非标准的伪选择器。

如果你想自己实现这个, jQuery如何实现它的:visible 选择器:
$ b


在jQuery 1.3.1旧的)如果一个元素的CSSdisplay不是none,它的CSSvisibility不是隐藏,并且它的类型(如果它是一个输入的话)不是隐藏的,那么这个元素是可见的。
在jQuery 1.3.2中,如果浏览器报告的offsetWidth或offsetHeight大于0,则元素是可见的。


http://docs.jquery.com/Release:jQuery_1.3.2 #:visible.2F:hidden_​​Overhauled


Is there anyway to use a pseudo selector with Firefox's querySelector() or querySelectorAll() functions to detect visibility? In particular I want to be able to do something like this:

elem.querySelector('#list .list-item:visible');
elem.querySelector('#section .sub-section:visible .title');

No need to worry about browser inconsistencies or other implementation, just Firefox. Thanks!

EDIT: Visible is defined by display not being none and visibility not being hidden.

解决方案

No, there isn't. The CSS specification doesn't define a :visible (or related) selector, and AFAIK Firefox doesn't implement non-standard pseudo selectors.

If you'd like to implement this yourself, note how jQuery implements its :visible selector:

In jQuery 1.3.1 (and older) an element was visible if its CSS "display" was not "none", its CSS "visibility" was not "hidden", and its type (if it was an input) was not "hidden". In jQuery 1.3.2 an element is visible if its browser-reported offsetWidth or offsetHeight is greater than 0.

Source: http://docs.jquery.com/Release:jQuery_1.3.2#:visible.2F:hidden_Overhauled

这篇关于Firefox,查询选择器和可见伪选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆