手机横竖屏切换时js获取手机有效宽值(兼容苹果和安卓)
// 横屏切换处理(iphone,安卓) window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function() { // 由于切换时,获取值刚好是切换前的数据,需加上300延时,保证获取的宽度是切换后屏幕的值 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);
// 由于安卓取的宽高有时未必是有效值,所以此处取最大的(用于遮罩层) function getMaxValue(num1,num2,num3) { var value = 0; if( num1 >= num2){ value = num1; }else { value = num2; } if( value< num3){ value = num3; } return value; }
// 默认取页面宽高的值 var height = $("body").height(); var width = $("body").width();
相关推荐
ydc0 2020-07-30
huningjun 2020-06-12
fanxiaoxuan 2020-06-03
Micusd 2020-11-19
liuxudong00 2020-11-19
星马殇 2020-11-18
章鱼之家 2020-10-29
leitingdulante 2020-10-21
88246630 2020-09-21
ZuoYanDeHuangHun 2020-09-18
bigname 2020-08-25
MatrixHero 2020-08-20
XxZproject 2020-08-10
定格 2020-08-15
panduola0 2020-08-05
quanhaoH 2020-07-31
yechen00 2020-07-25
是nsacer先森的 2020-07-02