iPad doesn't trigger resize event going from vertical to horizontal?

后端 未结 7 681
醉酒成梦
醉酒成梦 2020-12-08 00:33

Has anyone noticed this behavior? I\'m trying to write a script that will trigger upon a resize. It works fine on normal browsers, works fine on iPhone, but on iPad, will on

相关标签:
7条回答
  • 2020-12-08 01:28

    This includes all orientations.

    Here are two options:

    window.onorientationchange = function() {
    
        var orientation = window.orientation;
    
        // Look at the value of window.orientation:
    
        if (orientation === 0) {
        // iPad is in Portrait mode.
    
        } else if (orientation === 90) {
         // iPad is in Landscape mode. The screen is turned to the left.
    
        } else if (orientation === -90) {
         // iPad is in Landscape mode. The screen is turned to the right.
    
        } else if (orientation === 180) {
        // Upside down portrait.
    
        }
    }    
    

    or

    // Checks to see if the platform is strictly equal to iPad:
        if(navigator.platform === 'iPad') {
                window.onorientationchange = function() {
    
                var orientation = window.orientation;
    
                // Look at the value of window.orientation:
    
                if (orientation === 0) {
                // iPad is in Portrait mode.
    
                } else if (orientation === 90) {
                 // iPad is in Landscape mode. The screen is turned to the left.
    
                } else if (orientation === -90) {
                 // iPad is in Landscape mode. The screen is turned to the right.
    
                } else if (orientation === 180) {
                // Upside down portrait.
    
                }
              }       
            }
    
    0 讨论(0)
提交回复
热议问题