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

后端 未结 4 1573
野趣味
野趣味 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:21

    As far as I know screen the width/height will not change in the device after rotation. To check if the device is rotated you could read these properties

    1. window.orientation: This value change from 0 to +90/-90
    2. window.innerHeight/innerWidth: This values are swapped
    3. document.documentElement.clientHeight/clientWidth: This values are swapped

    Unfortunately, this behavior is not consistent across all Android/iOS/Window devices. I think it's pretty explained in this figure .

提交回复
热议问题