2008-12-02 62 views

回答

14

從Firefox的快速測試中,它看起來像大小和位置屬性(clientWidth,offsetTop等)全部返回0時,父元素被隱藏display:none

+3

好主意。甚至可以指定:http://www.w3.org/TR/cssom-view/#offset-attributes – Kornel 2008-12-03 00:15:16

+1

在當前的CSSOM View Module草案(2013)中,@Kornel發佈的鏈接不再指向正確的部分。查看[w3.org/TR/cssom-view/#dom-htmlelement-offsettop](http://www.w3.org/TR/cssom-view/#dom-htmlelement-offsettop)。 – falconepl 2015-10-10 18:15:56

1

使用Prototype

if($('someDiv').visible) {...} 
+2

如果您已經提供了Prototype的這個函數的源代碼,以顯示它如何實際完成,那將會更有幫助。 – 2008-12-04 15:47:29

+3

我只使用庫。我沒有寫。 – 2008-12-04 17:48:30

0

由於我使用的是MochiKit,我想出了基於螞蟻普的回答是:

getElementPosition('mydiv').y != 0 

我也可以檢查它是否在視(垂直)通過:

y = getElementPosition('mydiv').y 
(y < getViewportPosition().y + getViewportDimensions().h && 
    getViewportPosition().y < y) 

順便說一句,這也適用於IE6。

0

依靠位置爲0是脆弱的。你最好寫一個輔助函數來遍歷父母直接檢查他們的顯示風格。

0

這裏的迭代求解 -

var elementShown = function(e){ 
    if (e == document) 
     return true; 

    if ($(e).css('display') == 'none') //or whatever your css function is 
     return false; 

    return elementShown(e.parentNode); 
} 
相關問題