开发者

Resize javascript window

开发者 https://www.devze.com 2023-04-01 18:35 出处:网络
How would I apply a resize event to this code, so it gets the new height 开发者_JAVA百科of window if its changed

How would I apply a resize event to this code, so it gets the new height 开发者_JAVA百科of window if its changed

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


$(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(){}).


$(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(); });


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

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

Make sure its at the bottom of the page.

0

精彩评论

暂无评论...
验证码 换一张
取 消