简体   繁体   English

如何获取窗口视口大小?

[英]How can i get the window viewport size?

I tried to get the window viewport width. 我试图获取窗口视口宽度。 when i use document.documentElement.clientHeight(or)window.innerWidth i can get exactly what i need. 当我使用document.documentElement.clientHeight(或)window.innerWidth时,我可以完全得到所需的东西。 If i logged In at minimize mode,then if i maximize the window the viewport width will not be resized.I got the viewport width when it is minimized. 如果我以最小化模式登录,那么如果我最大化窗口,则视口宽度将不会调整。最小化时,我会得到视口宽度。 how can i slove it? 我怎样才能解决它? I also tried to use document.body.clientHeight .But here also i got problem.The viewport size is larger than my viewport,because of statusbar.Then i subtract the statusbar size,then i got the viewport size.If i have anotherbar in my window again i got the same problem. 我也尝试使用document.body.clientHeight 。但是在这里我也遇到了问题。由于状态栏的缘故,视口的尺寸大于我的视口。然后我减去状态栏的尺寸,然后得到了视口的尺寸。我的窗户又出现了同样的问题。 Exactly what i need is how can get the end user viewport size?Please help me? 我真正需要的是如何获得最终用户的视口大小?请帮帮我吗?

Thanks in advance 提前致谢

from the jQuery docs: 来自jQuery文档:

http://api.jquery.com/height/ http://api.jquery.com/height/
http://api.jquery.com/width/ http://api.jquery.com/width/

$(window).width();   // returns width of browser viewport
$(window).height();   // returns height of browser viewport

Try: 尝试:

$myviewport.getHeight();
$myviewport.getWidth();

Where myviewport is the viewport OBJECT. 其中myviewport是视口对象。 You can also use: 您还可以使用:

Ext.getCmp('myviewport').getHeight();
Ext.getCmp('myviewport').getWidth();

Where 'myviewport' is the ID of the viewport object. 其中“ myviewport”是视口对象的ID。

Use 采用

.getHeight(true);
.getWidth(true);

To get the height/width minus padding, margins, borders etc. 要获得高度/宽度减去填充,边距,边框等。

As a consequence of the proliferation of different browsers' ideas about this, it's a surprisingly tricky thing to get right. 由于不同浏览器对此想法的泛滥,正确的实现是一件非常棘手的事情。 David Mark (author of My Library ) is particularly strong in this area and has written an article on the subject: http://www.cinsoft.net/viewport.asp 大卫·马克(《 我的图书馆》的作者)在这方面尤为出色,并撰写了有关该主题的文章: http : //www.cinsoft.net/viewport.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM