简体   繁体   English

$(window).resize(); 不起作用 - 重新访问

[英]$(window).resize(); doesn't work - REVISIT

I have a script where I even out the heights of the content on containers inside a wrapper div.我有一个脚本,我在其中计算了包装器 div 内容器上内容的高度。 It simply won't recalculate/reset the height on resize (on refresh it works).它根本不会在resize重新计算/重置高度(刷新时它可以工作)。

I know this matter is answered in many places, and I believe I have read them all, but my script still wont run on resize.我知道很多地方都回答了这个问题,我相信我已经阅读了所有内容,但是我的脚本仍然无法在调整大小时运行。

Can you tell me what's wrong?你能告诉我有什么问题吗? Thanks!谢谢!

var $equalboxContainer = $('.equalbox-container');
if ($equalboxContainer.length) {
  function equalheight(container) {
    $(container).each(function() {
      var highestBox = 0;
      $('.equal-box', this).each(function() {
        if ($(this).height() > highestBox) {
          highestBox = $(this).height();
        }
      });
      $('.equal-box', this).height(highestBox);
    });
  };

  equalheight($equalboxContainer);

  $(window).resize(function() {
    equalheight($equalboxContainer);
  });
}

it works for me i dont understand why it wouldnt maybe try using the venila js alternative它对我有用,我不明白为什么它不会尝试使用 venila js 替代方案

 $(window).resize(function(e) { //adds events for func to console.log('resize') }); //end bracket // or venila js window.addEventListener('resize', function(e){ //adds events for func console.log('resize'); }); //end bracket
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM