javascript - 每行的子列相等

标签 javascript jquery html css

我有一个产品图库,父级和子级 div 的高度需要相等。

我需要按行计算它。但我得到了最高的 child ,它适用于所有的 div。我想要的是获得最高的 div 并按行应用它。

$(document).ready(function() {
 var item_title_height = 0;
 var item_details_height = 0;

 $('.item-title').each(function(i, obj) {
    if($(this).height() > item_title_height) {
    item_title_height = $(this).height();
  }
 });

 $('.item-details').each(function(i, obj) {
    if($(this).height() > item_details_height) {
    item_details_height = $(this).height();
  }
 });

$(".item-title").height(item_title_height);
$(".item-details").height(item_details_height);

});

这是我的 fiddle

fiddle

希望你能帮助我

最佳答案

不确定如何在 jQuery 中执行此操作。但你可以很容易地找到最大的 Vanilla div。使用 window.getComputedStyle 获取可能没有显式 css 或 html 样式声明的元素的样式信息。

var heights = Array.prototype.slice.call(document.getElementsByClassName('item-title')).map(function(i){
    var cs = window.getComputedStyle(i,null)
    return parseFloat(cs.getPropertyValue("height"))
});
alert(Math.max.apply(null,heights))

关于javascript - 每行的子列相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36728022/

相关文章:

javascript - 下拉列表触发jquery?

javascript - 使用 jQuery 在不同的 `div` 之间标记一行

打印时 HTML 将表格推到下一页

html - 所有链接到同一页面的相同颜色

Javascript - 查找对象的容器

javascript - JS在span中查找id

javascript - 将数据从 JQuery on click 函数传递到 PHP 服务器?

javascript - 将 JavaScript 变量值转换为 csv 文件

javascript - 从 React.JS 状态调用方法

javascript - 卓别林在获取后如何渲染模型? View 如何知道获取已完成?