[英]on window resize change div height in chrome
.content-block
類內容為動態文本,因此高度與每個div塊都不同。 使用div的javascript max height查找適用於其他div的高度,以便在瀏覽器中調整所有div的大小將具有相同的高度。 在大多數瀏覽器中都可以使用的偽代碼下方,但在chrome中,將瀏覽器調整為小於320x480的大小將不起作用。
<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;
}
如果可以將CSS flexbox用於此目的,則使用JavaScript可能會導致擴展問題。 這是CSS技巧參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.