Reputation: 10580
I have the following script that works okay if page is refreshed but I want to be able to dynamically get the size of the resized window without refreshing the page and apply respective height to a section.
var w = $(window).width();
var h = $(window).height();
$('section').height(h);
What am I missing to make it work more dynamically?
Upvotes: 2
Views: 1297
Reputation: 36794
Try the following, the function will be called every time the window is loaded or resized:
$(window).on('load resize', function(){
var w = $(window).width();
var h = $(window).height();
$('.section-content').height(h);
});
You confirmed in the comments that section
should in fact be .section-content
.
Upvotes: 4
Reputation: 206593
function setToWinSize(){
var win = $(window);
$('section').width(win.width()).height(win.height());
}
$(function(){ // on DOM ready
setToWinSize();
$(window).resize(function(){
setToWinSize();
});
});
Upvotes: 1
Reputation: 82251
Try setting height width on window resize.
Window resize height/width change Fiddle
Jquery:
$(window).on('resize', function(){
var h=($(window).height();
var w=$(window).width();
$('.section-content').height(h);
});
Upvotes: 1
Reputation: 2104
$(window).resize(function(){
var w = $(window).width();
var h = $(window).height();
$('.section-content').height(h);
});
Upvotes: 2