Javascript 如何使用 jquery 获取屏幕的“高度”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2407221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:10:49  来源:igfitidea点击:

How to get the 'height' of the screen using jquery

javascriptjquery

提问by zjm1126

I want to set something in the middle of the screen

我想在屏幕中间设置一些东西

thanks

谢谢

回答by Dustin Laine

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

As documented here: http://api.jquery.com/height/

如此处所述:http: //api.jquery.com/height/

回答by Piseth Sok

use with responsive website (view in mobile or ipad)

与响应式网站一起使用(在手机或 ipad 中查看)

jQuery(window).height();   // return height of browser viewport
jQuery(window).width();    // return width of browser viewport

rarely use

很少使用

jQuery(document).height(); // return height of HTML document
jQuery(document).width();  // return width of HTML document

回答by rahul

$(window).height();

To set anything in the middle you can use CSS.

要在中间设置任何内容,您可以使用 CSS。

<style>
#divCentre 
{ 
    position: absolute;
    left: 50%;
    top: 50%;
    width: 300px;
    height: 400px;
    margin-left: -150px;
    margin-top: -200px;
}
</style>
<div id="divCentre">I am at the centre</div>