当前位置: 首页 > Web前端 > HTML

适配iphoneX_0

时间:2023-04-03 00:28:22 HTML

tipsiphone6,设备宽高为375×667,屏幕分辨率为750×1334,所以设备像素比(dpr)为2。iphoneX的设备宽高为375*812,屏幕分辨率为1125x2436。所以dpr=3适合iphoneX。目前已知的方法有3种。前两种方法是先判断模型。设备宽高字符串iphone和iphoneXconstisIphoneX=()=>{return/iphone/gi.test(navigator.userAgent)&&(screen.height==812&&screen.width==375)}2.判断iphoneXmodel-2通过媒体查询,判断设备宽高和dpr@mediaonlyscreenand(device-width:375px)and(device-height:812px)and(-webkit-device-pixel-ratio:3){}3.iOS11中的WebKit包括一个新的CSS函数constant()通过css3的内容,以及一组四个预定义常量:safe-area-inset-left、safe-area-inset-right、safe-area-inset-top和safe-area-inset-bottombody{背景:灰色;padding-top:constant(safe-area-inset-top);padding-left:constant(safe-area-inset-left);padding-right:constant(safe-area-inset-right);padding-bottom:constant(safe-area-inset-bottom);}