【问题标题】:Why is this procedure not resizing the heights properly?为什么这个程序不能正确调整高度?
【发布时间】:2015-11-14 13:36:31
【问题描述】:

我有一个程序:

jQuery(window).load(function() {
    function rescaleStuff ( )
    {
        jQuery('.children-have-equal-height').each(function(){
            var children = jQuery(this).children();
            var numChildren = children.length;
            if (numChildren > 1) 
            {
                var firstChild = children.first();
                var maxHeight = firstChild.height();
                firstChild.siblings().each(function()
                { 
                    var thisHeight = jQuery(this).height(); 
                    if (thisHeight > maxHeight) 
                        maxHeight = thisHeight;
                });
                children.height(maxHeight);
            }
        });
    }

    rescaleStuff();

    jQuery(window).resize(function()
    { 
         rescaleStuff();
    });
});

这应该使类 children-have-equal-height 的所有子元素的高度相同,即最高子元素的高度。这适用于页面加载,但在随后调整窗口大小后,元素保持与页面加载时相同的高度。这是为什么呢?

【问题讨论】:

标签: javascript jquery dom responsive-design jquery-events


【解决方案1】:

正是因为这个功能jQuery(window).load(function() {}

它只在页面加载时触发。

jQuery(window).resize(function(){}function rescaleStuff ( ){}放上

jQuery(window).load(function() {}之外

【讨论】:

  • 否;他的代码也应该可以工作。 (在加载时添加事件也可以)
  • 如果他有它在外面,他可以在里面打电话给他们。对吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多