DOM event fired by window resize

后端 未结 5 2187
攒了一身酷
攒了一身酷 2021-02-10 04:34

I have a page that has a fairly complicated layout. When the page is initially opened there\'s a problem with the aligment of some of the elements. However, this problem can be

5条回答
  •  春和景丽
    2021-02-10 05:14

    There's an window.onresize event that fires when the window is resized. You can force a resize by changing the window.width or height by a pixel and then setting it back on a small timer.

    With jQuery you can do something like this:

    $(function() { 
       $(window).width($(window).width() + 1);
      // delay so DOM can update and not batch UI updates
      setTimeout(function() { $(window).width($(window).width() -1); },3);
    });
    

    FWIW, I've seen this myself before, but I agree with @bouke that you should defintitely try to identify what's causing the broken layout. I find it usually has to do with floated content or overflow of text containers that causes these sorts of problems.

提交回复
热议问题