1 回答
TA贡献1111条经验 获得超0个赞
尝试:
const updateSize = () => {
const Allitem = document.querySelectorAll('.item')
, MaxHeight = 0
Allitem.forEach(item=>{ item.style.minHeight = '' }) // remove values
MaxHeight = Array.from(Allitem).reduce((a,c)=>a<c.clientHeight?c.clientHeight:a,0)
Allitem.forEach(item=>{ item.style.minHeight = `${MaxHeight}px` })
}
对于只有同一行的单元格必须具有相同高度的情况:
const updateSize = () => {
const Allitems = document.querySelectorAll('.item')
let ItemsOnLine = []
, topPos = -99999
, MaxHeight = 0
const setHeights = h => ItemsOnLine.forEach(item=>{ item.style.minHeight = `${h}px` })
Allitems.forEach(item=>{ item.style.minHeight = '' }) // remove values
Allitems.forEach(item=>{
if (item.offsetTop != topPos)
{
setHeights(MaxHeight)
MaxHeight = 0
ItemsOnLine.length = 0
topPos = item.offsetTop
}
MaxHeight = Math.max(MaxHeight, item.clientHeight )
ItemsOnLine.push( item )
})
setHeights(MaxHeight)
}
添加回答
举报