Forcing windows resize to fire

后端 未结 6 1212
[愿得一人]
[愿得一人] 2020-12-14 15:57

I have problems with my layout, when I re-size window manually and restore it to normal everything is in the perfect place.

Is it possible to trick the browser and

6条回答
  •  醉酒成梦
    2020-12-14 16:25

    Following is the working solution:

    if (typeof(Event) === 'function') {
      // modern browsers
      window.dispatchEvent(new Event('resize'));
    } else {
      // for IE and other old browsers
      // causes deprecation warning on modern browsers
      var evt = window.document.createEvent('UIEvents'); 
      evt.initUIEvent('resize', true, false, window, 0); 
      window.dispatchEvent(evt);
    }
    

提交回复
热议问题