Steven Matthews
Steven Matthews

Reputation: 11275

Javascript Resize Element Based on Browser Height

I am trying to use Javascript/jQuery to resize part of a website based on the height of the window.

My code is as follows:

jQuery.event.add(window, "load", resizeFrame);
jQuery.event.add(window, "resize", resizeFrame);

function resizeFrame()
{
var h = $(window).height();
$(".main-wrapper").css('height', (h) ? h - 100);
}

What am I doing wrong? It doesn't seem to resize the section controlled by main-wrapper.

Upvotes: 0

Views: 332

Answers (1)

Will
Will

Reputation: 20235

You have an error in your conditional statement (h) ? h - 100. You have to provide a value for if (h) evaluates to false. The correct syntax is (cond ? exptrue : expfalse)

$(".main-wrapper").css('height', h ? h - 100 : default_value );

Upvotes: 2

Related Questions