https://www.cnblogs.com/moluy/p/14096634.html
/**判斷屏幕大小 */
function judgeBigScreen() { //,這里根據(jù)返回值 true 或false ,返回true的話 則為全面屏
let result = false;
const rate = window.screen.height / window.screen.width;
let limit = window.screen.height == window.screen.availHeight ? 1.8 : 1.65; // 臨界判斷值
// window.screen.height為屏幕高度
// window.screen.availHeight 為瀏覽器 可用高度
if (rate > limit) {
result = true;
}
return result;
};
//自動(dòng)執(zhí)行匿名函數(shù)
(function() {
$().ready(function() {
judgeBigScreen();//判斷手機(jī)是否為全面屏
});
})();
那么在小程序里怎么封裝? 其實(shí)差不多
/**判斷屏幕大小 */
judgeBigScreen() {
let result = false;
const res = wx.getSystemInfoSync();
const rate = res.windowHeight / res.windowWidth;
let limit = res.windowHeight == res.screenHeight ? 1.8 : 1.65; // 臨界判斷值
if (rate > limit) {
result = true;
}
return result;
}
Javascript判斷是否iphone全面屏手機(jī)
function testUA (str) {
return navigator.userAgent.indexOf(str) > -1
}
// 判斷是iphoneX及以后的iphone手機(jī)(即iphone帶全面屏的手機(jī))
var isNewIphone = window && testUA('iPhone') && window.screen.height >= 812 && window.devicePixelRatio >= 2;
原因:iphoneX及之后更新的iphone手機(jī),其window.screen.height最小是812,且window.devicePixelRatio最小是2。