jQuery resize event not firing

前端 未结 7 1600
独厮守ぢ
独厮守ぢ 2021-01-11 09:58

For whatever reason the following:

$(function() {
  $(window).resize(function() {
    alert(\"resized!\");
  });
});

only fires an event wh

7条回答
  •  半阙折子戏
    2021-01-11 10:57

    I was with the same problem, saw all kind of solutions and didn't work.

    Making some tests I noticed that the $(window).resize, at least in my case, would only trigger with $(document).ready() before it. Not $(function()); nor $(window).ready();

    So my code now is:

    $(document).ready(function(){
      $(window).resize(function(){
          // refresh variables
          // Apply variables again
      });
    });
    

    ...and even an alert work!

提交回复
热议问题