jQuery窗口调整大小触发警报,不触发功能

时间:2019-01-22 12:43:13

标签: javascript jquery css

页脚中包含以下代码:

<script type="text/javascript">
    jQuery(document).ready(function($){
      var maxHeight1 = 0; $(".header-primary").each(function(){ if ($(this).height() > maxHeight1) { maxHeight1 = $(this).height(); } }); $(".header-primary").height(maxHeight1);
      var maxHeight2 = 0; $(".header-secondary").each(function(){ if ($(this).height() > maxHeight2) { maxHeight2 = $(this).height(); } }); $(".header-secondary").height(maxHeight2);
    });

<script type="text/javascript">
    jQuery(window).resize(function($){
      alert('I fire');
      var maxHeight1 = 0; $(".header-primary").each(function(){ if ($(this).height() > maxHeight1) { maxHeight1 = $(this).height(); } }); $(".header-primary").height(maxHeight1);
      var maxHeight2 = 0; $(".header-secondary").each(function(){ if ($(this).height() > maxHeight2) { maxHeight2 = $(this).height(); } }); $(".header-secondary").height(maxHeight2);
    });
</script>

第一部分可以正常工作。当我刷新/打开页面时,此JS代码中提到的具有CSS类的元素大小相同(最大)。

当谈到window.resize部分时,它根本不起作用。我已经尝试过各种包装器来满足Firebug的要求,但是即使它没有显示错误,该脚本仍然无法正常工作。用于测试目的的警报可以正常工作,因此window.resize可以正确触发。

我通常使用搜索引擎找到解决方案,但这是一个例外。 :(

HTML:

<div class="block">

  <div class="block-big-item">

    <h3 class="header-primary">BIG ITEM</h3>

  </div>

  <div class="block-small-items">

    <div class="block-small-item">
      <h3 class="header-secondary">SMALL ITEM</h3>
    </div>

    <div class="block-small-item">
      <h3 class="header-secondary">SMALL ITEM</h3>
    </div>

  </div>

</div>

0 个答案:

没有答案
相关问题