When the mobile phone is switched between horizontal and vertical screen, js obtains the effective width value of the mobile phone (compatible with Apple and Android)

// Horizontal screen switching processing (iphone, Android)
    window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function() {
        // Since when switching, the acquired value is just the data before switching, and a delay of 300 needs to be added to ensure that the acquired width is the value of the screen after switching
        setTimeout(function(){
            var scrollHeight = getMaxValue(document.documentElement.clientHeight, document.body.clientHeight, window.screen.height);
            var scrollwidth = getMaxValue(document.documentElement.clientWidth, document.body.clientWidth, window.screen.width);
            $("#black_marsk").height(scrollHeight);
            $("#black_marsk").width(scrollwidth);
        },300);

    }, false);

// Since the width and height taken by Android may not be valid sometimes, the largest one is taken here (for the mask layer)
function  getMaxValue(num1,num2,num3) {
    var value = 0;
    if( num1 >= num2){
        value = num1;
    }else {
        value = num2;
    }
    if( value< num3){
        value = num3;
    }
    return value;
}
// By default take the value of the page width and height
var height = $("body").height();
var width = $("body").width();
 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326569362&siteId=291194637