ipadLandscape.js
895 字节
var supportsOrientationChange = "onorientationchange" in window,
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
// 监听事件
window.addEventListener(orientationEvent, function () {
var ua = navigator.userAgent;
var deviceType = "";
//判断设备类型
if (ua.indexOf("iPad") > 0) {
deviceType = "isIpad";
} else if (ua.indexOf("Android") > 0) {
deviceType = "isAndroid";
} else {
// console.log("既不是ipad,也不是安卓!");
return;
}
let ipadId = document.getElementById('orientLayer')
// 判断横竖屏
if ("isIpad" == deviceType) {
if (Math.abs(window.orientation) == 90) {
ipadId.style.display = 'block'
// console.log("我是ipad的横屏",ipadId.style.display = 'block');
} else {
// console.log("我是ipad的竖屏");
ipadId.style.display = 'none'
}
}
}, false);