4

I have 2 elements on a page, a title and content area for people to enter text.

The contents height is determined using JavaScript:

$('#body').css('min-height', $(window).height() - $('#title').height() - 220);

Is there a way I can have it so when the window is resized, the #body changes its height?

user2203362
  • 259
  • 1
  • 7
  • 11

2 Answers2

3

Yep, it's possible - just add the resize event handler like this:

$(window).resize(function() {
    $('#body').css('min-height', $(window).height() - $('#title').height() - 220);
});
bniwredyc
  • 8,649
  • 1
  • 39
  • 52
0

Try this DEMO

Change re-size code as you want

$(window).bind('resize', function () { 
    $('#body').css('min-height', $(window).height() - $('#title').height());
});
Subodh Ghulaxe
  • 18,333
  • 14
  • 83
  • 102
  • resize jfiddle output window – Subodh Ghulaxe Apr 06 '13 at 11:16
  • What's the different between using `.bind()` rather than `.resize()` like in the answer above? Does it do something different? – user2203362 Apr 06 '13 at 11:27
  • This two links will help you to understand http://www.elijahmanor.com/2012/02/differences-between-jquery-bind-vs-live.html http://stackoverflow.com/questions/4865566/in-jquery-when-should-you-use-bind-over-click-or-any-other-given-event – Subodh Ghulaxe Apr 06 '13 at 11:52