简体   繁体   English

新秀:需要window.onresize

[英]Rookie: window.onresize needed

I'm a rookie when it comes to programming, so I really need your help here. 我是编程方面的新秀,因此在这里我真的需要您的帮助。 I need to change some code to fulfil my needs and I can't seem to do it in a proper way. 我需要更改一些代码来满足我的需求,但是我似乎无法以适当的方式做到这一点。 What I need right now, is to take this script and make it work when the $(window).width > 480 . 我现在需要的是使用此脚本,并在$(window).width> 480时使其工作。 Also, I need this script to run every time the user resizes the window. 另外,每次用户调整窗口大小时,我都需要运行此脚本。

I apologise for my silly question, but I'm just starting to learn the basics about Javascript and Jquery, and I can't seem to find the answer to this question this time. 对于这个愚蠢的问题,我深表歉意,但是我才刚刚开始学习有关Javascript和Jquery的基础知识,而这次我似乎找不到该问题的答案。

Here is the code 这是代码

      $(window).load(function(){
    (function($) {

      $.fn.eqHeights = function() {

          var el = $(this);
          if (el.length > 0 && !el.data('eqHeights')) {
              $(window).bind('resize.eqHeights', function() {
                  el.eqHeights();
              });
              el.data('eqHeights', true);
          }
          return el.each(function() {
              var curHighest = 0;
              $(this).children().each(function() {
                  var el = $(this),
                      elHeight = el.height('auto').height();
                  if (elHeight > curHighest) {
                      curHighest = elHeight;
                  }
              }).height(curHighest);
          });
      };

      $('.articles_container').eqHeights();

  }(jQuery));
  });

To execute it on window resized, do this: 要在调整大小的窗口上执行它,请执行以下操作:

$(window).resize(function() {
   $('.articles_container').eqHeights();
}

Also, if you want to execute javascript upon media queries events, then use the sweet enquire.js javascript library. 另外,如果您想在媒体查询事件时执行javascript,请使用sweet enquire.js javascript库。

The window has an .innerWidth property which I presume is still accessible through jQuery. 该窗口具有.innerWidth属性,我认为仍然可以通过jQuery访问。 so your code might be something like this: 因此您的代码可能是这样的:

$(window).resize(function() {
   if($(window).innerWidth < 480) return;
   $('.articles_container').eqHeights();
})

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

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