1 回答
TA贡献1811条经验 获得超4个赞
我自己找到了解决方案:基本上我引入了一个数组,它将最大 OffsetHeight 存储在行中,然后将其应用于所有 div.cards,在完成该行后,它将进行清理,以便他可以填充新行 eccetera 的数据...
断续器
window.addEventListener('resize', function(event){
resetTable();
resizeTable();
});
function resetTable() {
var table = document.getElementById("table");
var row, n, column, m;
for (row = 0, n = table.rows.length; row < n; row++) {
for (column = 0, m = table.rows[row].cells.length; column < m; column++) {
//console.log('Row: ' + [row] + ' Column:' + [column] + ' clHeight: ' + table.rows[row].getElementsByClassName("card")[column].offsetHeight);
table.rows[row].getElementsByClassName("card")[column].style.minHeight = 'auto';
}
}
}
function resizeTable() {
//console.log('Rows: ' + document.getElementById("table").rows.length);
var table = document.getElementById("table");
var row, n, column, m, mColumn, t, arr = [];
for (row = 0, n = table.rows.length; row < n; row++) {
for (column = 0, m = table.rows[row].cells.length; column < m; column++) {
//console.log('Row: ' + [row] + ' Column:' + [column] + ' clHeight: ' + table.rows[row].getElementsByClassName("card")[column].offsetHeight);
arr.push(table.rows[row].getElementsByClassName("card")[column].offsetHeight);
}
for (mColumn = 0, t = table.rows[row].cells.length; mColumn < t; mColumn++) {
//console.log('Row: ' + [row] + ' Column:' + [mColumn] + ' clHeight: ' + Math.max.apply(Math, arr));
table.rows[row].getElementsByClassName("card")[mColumn].style.minHeight = Math.max.apply(Math, arr) + 'px';
}
arr = [];
}
}
添加回答
举报