我遇到了解决这个问题的问题。我正在使用jQuery调用resizeWindow函数,以便在调整浏览器窗口大小时运行。 resizeWindow函数按预期工作,但调整浏览器窗口大小似乎不会调用该函数再次运行。
$(document).ready(function(){
//Bind the window onresize event
$(window).bind('resize', resizeWindow);
//Call resizeWindow() function immediately to intially set elements
$(window).bind('load', resizeWindow);
});
function resizeWindow(){
//Find all the container parent objects
$('.container').each(function(){
//Initialize the height variable
var maxHeight = 0;
//Cache the jQuery object for faster DOM access and performance
var $borders = $(this).find('.border');
//Find all the border child elements within this specific container
$borders.each(function(){
//Get current element's height
var thisHeight = $(this).height();
//Check if the current height is greater than the max height thus far
//If so, change max height to this height
if (thisHeight>maxHeight) maxHeight = thisHeight;
});
//Now that we have the maximum height of the elements,
//set that height for all the .border child elements inside the parent element
$borders.height(maxHeight);
});
}
答案 0 :(得分:2)
我相信你在第一次调用函数时手动设置边框的高度,它会在调整窗口大小时停止调整大小。
尝试在var $borders
之后添加此行:
$borders.css({height:'auto'});