我有一些具有相同高度的div,通过以下函数确定:
function equalHeights() {
var sameHeightDivs = $('.equal-heights');
var maxHeight = 0;
sameHeightDivs.each(function() {
maxHeight = Math.max(maxHeight, $(this).outerHeight());
});
sameHeightDivs.css({ height: maxHeight + 'px' });
}
equalHeights($('.equal-heights'));
$(window).resize(function(){
equalHeights($('.equal-heights'));
});但是,当窗口调整大小时,它基本上保持div高度的两倍。我的目的只是简单地重新计算div高度。
发布于 2021-06-23 12:23:21
function equalHeights() {
var sameHeightDivs = $('.equal-heights');
var maxHeight = 0;
sameHeightDivs.each(function() {
maxHeight = Math.max(maxHeight, $(this).outerHeight());
});
// **** clear old css height before put in a new one *****
sameHeightDivs.css({"height":""});
sameHeightDivs.css({ height: maxHeight + 'px' });
}
equalHeights($('.equal-heights'));
$(window).resize(function(){
equalHeights($('.equal-heights'));
});https://stackoverflow.com/questions/68092914
复制相似问题