[英]Content height of div with overflow:auto
如何使用javascript找出div内具有设置高度和overflow:auto的内容的高度?
You can just wrap the content inside another div and then you can use .offsetHeight
on this internal div... 您可以将内容包装在另一个div中,然后可以在此内部div上使用
.offsetHeight
...
<!DOCTYPE HTML>
<html>
<body>
<div style="background-color:#EEEEEE; height:400px; overflow:auto; width:100%">
<div id="container">
<p>The quick brown fox jumps over the lazy dog</p>
<p>The quick brown fox jumps over the lazy dog</p>
... snip ...
<p>The quick brown fox jumps over the lazy dog</p>
<p>The quick brown fox jumps over the lazy dog</p>
</div>
</div>
<script>
setTimeout(function() {
var container = document.getElementById("container");
alert("Container height = " + container.offsetHeight);
}, 1000);
</script>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.