检测相对于窗口的div高度?

时间:2015-04-10 14:36:11

标签: jquery

这里是我的jQuery代码,我想给出相对于窗口高度的div #topImgs高度,它是如何工作的?

$("#topImgs").css("height", function(){
        $( window ).height();
});

1 个答案:

答案 0 :(得分:0)

看起来你需要返回窗口的高度:

Example Here

$("#topImgs").css("height", function () {
    return $(window).height();    /* Some calculation here.. */
});
$("#topImgs").css("height", $(window).height());

你可能实际上并不需要jQuery。在supported browsers中,您可以使用viewport-relative units, vh

Example Here

#topImgs {
    height: 100vh;
}