screen.width/screen.height not updating after screen rotation

后端 未结 4 1572
野趣味
野趣味 2021-02-13 02:58

I\'m experiencing this problem on an iPhone device (iPhone 7, iOS 10, but also other iPhones too): in javascript, if I intercept the orientationchange event, inside the handler,

4条回答
  •  执笔经年
    2021-02-13 03:27

    CSS can't detect the orientation change.

    Use JavaScript to get the orientation change.

    Add the function as

    window.addEventListener("orientationchange", function() {
      document.body.style.width = window.innerWidth;
    });
    

    This will add an event Handler to window to change the width of body when the orientation is changed.

    More reference on orientationchange

提交回复
热议问题