【转】JavaScript 判断iPhone X Series机型的方法
<p>https://www.jb51.net/article/155482.htm</p><div class="cnblogs_code">
<pre>const isIphonex = () =><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> X XS, XS Max, XR</span>
const xSeriesConfig =<span style="color: rgba(0, 0, 0, 1)"> [
{
devicePixelRatio: </span>3<span style="color: rgba(0, 0, 0, 1)">,
width: </span>375<span style="color: rgba(0, 0, 0, 1)">,
height: </span>812<span style="color: rgba(0, 0, 0, 1)">,
},
{
devicePixelRatio: </span>3<span style="color: rgba(0, 0, 0, 1)">,
width: </span>414<span style="color: rgba(0, 0, 0, 1)">,
height: </span>896<span style="color: rgba(0, 0, 0, 1)">,
},
{
devicePixelRatio: </span>2<span style="color: rgba(0, 0, 0, 1)">,
width: </span>414<span style="color: rgba(0, 0, 0, 1)">,
height: </span>896<span style="color: rgba(0, 0, 0, 1)">,
},
];
</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> h5</span>
<span style="color: rgba(0, 0, 255, 1)">if</span> (<span style="color: rgba(0, 0, 255, 1)">typeof</span> window !== 'undefined' &&<span style="color: rgba(0, 0, 0, 1)"> window) {
const isIOS </span>= /iphone/<span style="color: rgba(0, 0, 0, 1)">gi.test(window.navigator.userAgent);
</span><span style="color: rgba(0, 0, 255, 1)">if</span> (!isIOS) <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
const { devicePixelRatio, screen } </span>=<span style="color: rgba(0, 0, 0, 1)"> window;
const { width, height } </span>=<span style="color: rgba(0, 0, 0, 1)"> screen;
</span><span style="color: rgba(0, 0, 255, 1)">return</span> xSeriesConfig.some(item => item.devicePixelRatio === devicePixelRatio && item.width === width && item.height ===<span style="color: rgba(0, 0, 0, 1)"> height);
}
</span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
}</span></pre>
</div><br><br>
来源:https://www.cnblogs.com/realwds/p/12073940.html
頁:
[1]