Created
January 18, 2019 04:58
-
-
Save if540/20549d0c193fb7a864b7f548cb406f07 to your computer and use it in GitHub Desktop.
檢測設備顯示特徵(Detecting the Device's Display Characteristics)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 檢試是否為行動裝置 | |
function isMobile() { | |
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { | |
retrun true | |
} else { | |
return false | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 檢試裝置方向 | |
// window.orientation 已棄用 | |
// window.screen.orientation.type safari no support - https://developer.mozilla.org/zh-TW/docs/Web/API/Screen/orientation | |
function detectOrientation() { | |
let query = window.matchMedia("(orientation:landscape)"); | |
let result = query.matches ? 'landscape' : 'portrait' | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment