When resized, it does not update the height. Once the load has set its height, it will not be updated, even though I am updating the variable.
If I take out the lines where it sets the height, then my variable is updated normally, but as soon as the height is set, it does nothing.
Where am I wrong?
var hero_height = $('.hero-image').outerHeight(); console.log('heroHeight: ' + hero_height); $(document).ready(function() { $(window).load(function() { $('.hero-image').css('height', hero_height ); }); $(window).resize(function() { if (hero_height !== $('.hero-image').outerHeight()) { $('.hero-image').css('height', hero_height ); }; hero_height = $('.hero-image').outerHeight(); console.log('heroHeight: ' + hero_height); }); });
Here is the JS fiddle
https://jsfiddle.net/5c1za6xa/
source share