为什么在调整 window 大小时无法为多列设置相同的高度?
Why is setting same height for multiple columns not working when resizing window?
我有一个函数可以为带有文本的列设置相同的高度。
它在桌面上工作正常,但在调整 window 的大小时没有任何作用。
有什么问题?
代码如下。谢谢
function columnSize() {
var maxheight = 0;
$('.service .wrap .intro').each(function() {
if($(this).innerHeight() > maxheight) { maxheight = $(this).innerHeight(); }
});
$('.service .wrap .intro').innerHeight(maxheight);
}
$(document).ready(function() {
columnSize();
});
$(window).resize(function(){
columnSize();
});
问题是页面首次加载时 div 设置了高度。这会在 div 上设置一个样式属性,因此当您再次检查 div 的高度时,它只会提取该值,这就是它永远不会改变的原因。在再次设置它们之前,您需要将高度重置为自动
看这里http://jsfiddle.net/rhboyzgx/2/
function columnSize() {
var maxheight = 0;
var $intros = $('.service .wrap .intro');
$intros.css("height","auto");
$intros.each(function() {
var h = $(this).innerHeight();
if( h > maxheight ) {
maxheight = h;
}
});
$intros.innerHeight(maxheight);
}
$(document).ready(function() {
columnSize();
});
$(window).resize(function(){
columnSize();
});
我有一个函数可以为带有文本的列设置相同的高度。
它在桌面上工作正常,但在调整 window 的大小时没有任何作用。
有什么问题?
代码如下。谢谢
function columnSize() {
var maxheight = 0;
$('.service .wrap .intro').each(function() {
if($(this).innerHeight() > maxheight) { maxheight = $(this).innerHeight(); }
});
$('.service .wrap .intro').innerHeight(maxheight);
}
$(document).ready(function() {
columnSize();
});
$(window).resize(function(){
columnSize();
});
问题是页面首次加载时 div 设置了高度。这会在 div 上设置一个样式属性,因此当您再次检查 div 的高度时,它只会提取该值,这就是它永远不会改变的原因。在再次设置它们之前,您需要将高度重置为自动
看这里http://jsfiddle.net/rhboyzgx/2/
function columnSize() {
var maxheight = 0;
var $intros = $('.service .wrap .intro');
$intros.css("height","auto");
$intros.each(function() {
var h = $(this).innerHeight();
if( h > maxheight ) {
maxheight = h;
}
});
$intros.innerHeight(maxheight);
}
$(document).ready(function() {
columnSize();
});
$(window).resize(function(){
columnSize();
});