egyflad
egyflad

Reputation: 33

Detect the div hight relative to the window?

here is my jQuery code, i want to give the div#topImgs height relative to the window height, how it works ?

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

Upvotes: 1

Views: 27

Answers (1)

Josh Crozier
Josh Crozier

Reputation: 240938

It looks like you need to return the height of the window:

Example Here

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

You may not actually need jQuery for this, though. In supported browsers, you can use viewport-relative units, vh:

Example Here

#topImgs {
    height: 100vh;
}

Upvotes: 1

Related Questions