/* js 判斷手機(jī)是否全面屏 */

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。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容