我正在使用这个 js 使两个 div 具有相同的高度,这适用于静态内容,但是当动态加载图像/内容时,高度被设置为 0px,因为我想脚本在内容被拉出之前触发. 有没有办法将其延迟几秒钟以设置正确的高度?尝试了超时功能,但无法使其正常工作
// make stuff the same height
equalheight = function (container) {
var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;
$(container).each(function () {
$el = $(this);
$($el).height('auto')
topPostion = $el.position().top;
if (currentRowStart != topPostion) {
for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
rowDivs.length = 0; // empty the array
currentRowStart = topPostion;
currentTallest = $el.height();
rowDivs.push($el);
} else {
rowDivs.push($el);
currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
}
for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
});
}
$(window).load(function () { equalheight('.equal'); });
$(window).resize(function () { equalheight('.equal'); });