简体   繁体   中英

Matching div height to parents , on window resize and load

I am able to match a child container to the parents height on page load, however my issue is getting it to match the parents height when resizing the window, here is my code so far:

HTML:

<div id="ocg-hero" class="container">
 <div class="row">

  <div class="large-6 columns heroContent"> </div>
  <div class="large-6 columns heroGraphic" > </div>

 </div>
</div>

Script :

function heroImageResize (){
    var heroHeight = $("#ocg-hero .row").height(),
        heroGraphicHeight = $(".heroGraphic").height();

        $(".heroGraphic").css("height",heroHeight);
};

heroImageResize();

Thanks!

对于两个处理程序:

$(window).on('load resize',heroImageResize);

jQuery has an event for resizing, you can use that for recalculating your height.

http://api.jquery.com/resize/

$(function(){   
   $(window).resize(heroImageResize);
});

as you it on page load also -

$(function(){  
  $(window).resize(heroImageResize).resize();
});

you can use resize http://api.jquery.com/resize/

$(window).resize( heroImageResize);
$(document).ready(function(){ $(window).resize(); /*triggers it*/  })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM