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

时间:2010-03-09 07:11:45

标签: javascript jquery

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

感谢

3 个答案:

答案 0 :(得分:150)

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

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

答案 1 :(得分:5)

与响应式网站一起使用(在移动设备或ipad中查看)

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

很少使用

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

答案 2 :(得分:2)

$(window).height();

要设置中间的任何内容,您可以使用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>