Resize javascript window
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.
精彩评论