简体   繁体   中英

on window resize change div height in chrome

.content-block class content dynamic text, so height is different to each div block. Using javascript max height of div find apply to other div's so on browser resize all div will same height. Below pseudo code working in most of the browser, but in chrome, browser resize less than 320x480 will not work.

<script type="text/javascript">
function getMaxHeight(){ 
    return maxHeight = Math.max.apply(null, $(".content-block").map(function (){
         return $(this).height();
     }).get());
}

$(window).resize(function(){
    $('.content-block').css('height', 'auto');
    $('.content-block').css('height', getMaxHeight);
});

$('.content-block').css('height', getMaxHeight);
</script>
<style>
.content-block{
    height: auto;
    display: block;
}

If you can use css flexbox for this purpose, using JavaScript might lead to scaling issues. Here is CSS-Tricks Reference

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