js判斷當前手機是否有touch bar
阿新 • • 發佈:2022-11-29
參考資料:https://useyourloaf.com/blog/iphone-12-screen-sizes/
export const hasBottomToolBar = () => { return ( /iphone/gi.test(navigator.userAgent) && window.devicePixelRatio && window.devicePixelRatio >= 2 && window.screen.height >= 812 ) }
export function isIphonex() { // 判斷是不是X型別手機 // X XS, XS Max, XR,11, 11pro,11pro max,12mini,12, 12 pro,12 pro max const xSeriesConfig = [ { devicePixelRatio: 3, width: 375, height: 812, }, { devicePixelRatio: 3, width: 414, height: 896, }, { devicePixelRatio: 2, width: 414, height: 896, }, { devicePixelRatio: 3, width: 315, height: 812, }, { devicePixelRatio: 3, width: 390, height: 844, }, { devicePixelRatio: 3, width: 428, height: 926, } ]; // h5 if (typeof window !== 'undefined' && window) { const isIOS = /iphone/gi.test(window.navigator.userAgent); if (!isIOS) return false; const { devicePixelRatio, screen } = window; const { width, height } = screen; return xSeriesConfig.some(item => item.devicePixelRatio === devicePixelRatio && item.width === width && item.height === height); } return false; }