-4

我在让它工作时遇到问题。我正在使用 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);
    });
}
4

1 回答 1

2

我相信您在第一次调用该函数时手动设置了边框的高度,它会在调整窗口大小时停止调整大小。

尝试在之后添加此行var $borders

$borders.css({height:'auto'});
于 2013-03-05T15:53:52.793 回答