美文网首页
/* js 判断手机是否全面屏 */

/* js 判断手机是否全面屏 */

作者: beforerFE | 来源:发表于2021-05-18 11:15 被阅读0次

https://www.cnblogs.com/moluy/p/14096634.html

/**判断屏幕大小 */
  function  judgeBigScreen() {  //,这里根据返回值 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;
    };
   
    //自动执行匿名函数
(function() {
    $().ready(function() {
        judgeBigScreen();//判断手机是否为全面屏
    });
})();

那么在小程序里怎么封装? 其实差不多

/**判断屏幕大小 */
  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全面屏手机

function testUA (str) {
  return navigator.userAgent.indexOf(str) > -1
}
// 判断是iphoneX及以后的iphone手机(即iphone带全面屏的手机)
var isNewIphone = window && testUA('iPhone') && window.screen.height >= 812 && window.devicePixelRatio >= 2;

原因:iphoneX及之后更新的iphone手机,其window.screen.height最小是812,且window.devicePixelRatio最小是2。

相关文章

网友评论

      本文标题:/* js 判断手机是否全面屏 */

      本文链接:https://www.haomeiwen.com/subject/yfmejltx.html