当元素的样式为"width:100%; height:auto;"时,如何获得该元素的确切像素高度或宽度?
我不能将其嵌套在div中并通过这种方式获取高度/宽度!
我猜想javascript可以在这里提供帮助。
编辑:我正在使用以下内容:
var collectNodes = document.getElementById('fade').children;
collectNodes[y].height() // ??
以下代码会输出字符串 "auto":
```html
以下代码提供了字符串 "auto":
```collectNodes[0].style.height;
编辑2:这是我的代码。
<div id="divId">
<img class="node" src="somePic0.png" style="z-index:10; opacity:0;"/>
<img class="node" src="somePic1.png" style="z-index:9; opacity:0;"/>
<img class="node" src="somePic2.png" style="z-index:8; opacity:1;"/>
<img class="node" src="somePic3.png" style="z-index:7; opacity:1;"/>
<img class="node" src="somePic4.png" style="z-index:6; opacity:1;"/>
</div>
<script>
var collectNodes = document.getElementById('divId').children;
var y = 0;
for ( var x = 0; x < collectNodes.length; x++ ) {
if ( collectNodes[x].style.opacity !== "" && !y ) {
y = x;
}
}
alert(collectNodes[y].height); // This alerts the string "auto" and not pixel height
</script>