【问题标题】:on window resize change div height in chrome在窗口调整大小更改 chrome 中的 div 高度
【发布时间】:2013-11-20 03:05:07
【问题描述】:

.content-block 类内容动态文本,因此每个 div 块的高度不同。使用 javascript max height of div find 适用于其他 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;
}

【问题讨论】:

  • 你可以使用display: table-cell来做同样的事情。这里不需要javascript。

标签: javascript jquery css twitter-bootstrap cross-browser


【解决方案1】:

如果您可以为此目的使用 css flexbox,则使用 JavaScript 可能会导致缩放问题。这里是CSS-Tricks Reference

【讨论】:

    猜你喜欢
    • 2011-02-15
    • 2013-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 2014-05-16
    相关资源
    最近更新 更多