Change variable on resize?

1.7k Views Asked by At

I'm trying to make the containerHeight variable change depending on the width of the browser. This is what I have so far but I'm not sure how to proceed even after reading the docs. Can someone help me out?

var containerHeight = $('#project-container').outerHeight();
window.onresize = containerHeight;
$('#project-wrapper.activated').css('max-height', containerHeight);
2

There are 2 best solutions below

0
On BEST ANSWER

Add "px" to the end. Or 'em', whatever you're using

$(window).on('resize', function() {
    var containerHeight = $('#project-container').outerHeight();
    $('#project-wrapper.activated').css('max-height', containerHeight + 'px');
});
0
On

What I would do is add an event listener for the window resize event:

window.addEventListener( 'resize', onWindowResize, false );

and then change that variable in the callback:

function onWindowResize() { }