jQuery resize event not firing

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

For whatever reason the following:

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

only fires an event wh

7条回答
  •  萌比男神i
    2021-01-11 10:43

    5 years later...

    The only browser I have this problem with, is Chrome; I don't have Safari.

    The pattern I noticed is that it works when I inline the code:

    
    

    but not when I put it in a separate Javascript file that I load with:

    
    

    where the script contains

    console.log('script loaded');
    $(window).resize(function(e) { console.log("resize in script file", +new Date()) });
    

    I can only guess this is some kind of "protection" built in by the Chrome development team, but it is silly and annoying. At least they could have let me bypass this using some "same domain policy".

    Update for a while I thought using $(document).ready() fixed it, but apparently I was wrong.

提交回复
热议问题