javascript如何获取动态高度(当我调整浏览器大小) [英] javascript How to get dynamically height (when i resize browser)

查看:780
本文介绍了javascript如何获取动态高度(当我调整浏览器大小)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从可调整的 div 中获得 height ,因为我想将溢出样式添加到 css ,当height值将大于一个设置值。当你调整窗口高度这个div改变。我将用一些图片解释这一点:

I'm trying to get height from adjustable div because I'd like to add overflow style into css when height value will be greater than a set value. When you resize window height of this the div change. I'll explain this with some pictures:

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

The main problem is how to get it dynamically? I mean,when you resize your own window etc.?

推荐答案

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

In case you are able to use jQuery, I would suggest using the window.onresize method and compute the height of the div.

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

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

Take a look at this fiddle I created for you: http://jsfiddle.net/9ftGe/

我希望这是你想要的。

这篇关于javascript如何获取动态高度(当我调整浏览器大小)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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