0

我试图height从可调节中获取,div因为我想css在高度值大于设定值时添加溢出样式。当您调整此 div 的窗口高度时,会发生变化。我将用一些图片来解释这一点:

http://imageshack.us/a/img801/2113/somethingo.png

http://imageshack.us/a/img7/7503/blebvle.png

主要问题是如何动态获取它?我的意思是,当你调整自己的窗口等时?

4

2 回答 2

3

如果您能够使用 jQuery,我建议您使用 window.onresize 方法并计算 div 的高度。

$(document).ready(function()
{
   $(window).on("resize", function()
   {
        $("#myDiv").text("My height is " + $("#myDiv").height());
   });                                                           
});​

看看我为你创建的这个小提琴:http: //jsfiddle.net/9ftGe/

我希望这是你想要的。

于 2012-11-11T20:10:47.360 回答
0

I think you're looking for monitoring the browser variables...

window.innerHeight

window.innerWidth

Whenever you check/call these variables you should get the exact window inner size and take it from there.

NB: These variables (constants to us) are case sensitive.

于 2012-11-11T20:07:03.517 回答