Uriah
Uriah

Reputation: 23

Resize javascript window

How would I apply a resize event to this code, so it gets the new height of window if its changed

$(document).ready(function() {
    $("#page").height($(window).height()); 
});

Upvotes: 2

Views: 1976

Answers (3)

Wilkins
Wilkins

Reputation: 185

$("#page").click(function () {  
  showHeight("window", $(window).height());  
}); 

http://api.jquery.com/height/

Make sure its at the bottom of the page.

Upvotes: 0

Robert Koritnik
Robert Koritnik

Reputation: 105029

$(function() {

    $(window).resize(function(){
        $("#page").height($(this).height());
    }).resize();

});

As you may see I've also shortened the $(document).ready(function(){}) by simply doing the $(function(){}).

Upvotes: 4

Marc Uberstein
Marc Uberstein

Reputation: 12541

$(window).resize(function() { 
  $(document).ready(function() {
        $("#page").height($(window).height()); 
  });
});

Should work fine.

OR [better formatting]

function resizePage()
{
      $(function() {
            $("#page").height($(window).height()); 
      });
}

$(window).resize(function() { resizePage(); });

Upvotes: 0

Related Questions