我有一个产品图库,父级和子级 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
希望你能帮助我
最佳答案
不确定如何在 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/