javascript How to get dynamically height (when i resize browser)

大憨熊 提交于 2019-12-11 17:49:17

问题


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.?


回答1:


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());
   });                                                           
});​

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

I hope this is what you wanted.




回答2:


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.



来源:https://stackoverflow.com/questions/13334873/javascript-how-to-get-dynamically-height-when-i-resize-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!