判斷是安卓還是ios
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
判斷是不是橫屏
判斷窗口有沒有orientationchange(使用方向改變)這個方法喷屋,有就命中這個事件琳拨,沒有就命中“resize”事件-電腦端的改變窗口事件。
$(window).on("orientationchange",fun)
可監(jiān)聽移動設(shè)備方向改變時事件
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function() {
if (window.orientation === 180 || window.orientation === 0) {
//縱向視圖window.orientation返回 0
//縱向的:豎屏屯曹,隱藏遮罩層與提示
document.querySelector('.land').style.display = 'none';
}
if (window.orientation === 90 || window.orientation === -90 ){
//橫向視圖window.orientation返回 90 或 -90
//橫向的:顯示遮罩層與提示
document.querySelector('.land').style.display = 'block';
}
}, false);
-
window.orientation
屬性可設(shè)置不同使用方向
2018.4.20