Created
August 17, 2018 19:30
-
-
Save prof3ssorSt3v3/2b3f9b7d04362558a5ea8a95d96a930a to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Screen Orientation</title> | |
<meta name="viewport" content="width=device-width"> | |
<link rel="stylesheet" href="main.css"> | |
</head> | |
<body> | |
<header> | |
<h1>Screen Orientation</h1> | |
</header> | |
<main> | |
<div id="output"></div> | |
</main> | |
<script> | |
let orn = getOrientation(); | |
let out = document.getElementById('output'); | |
out.textContent = orn; | |
function getOrientation() { | |
let _orn = screen.msOrientation || | |
(screen.orientation || screen.mozOrientation).type; | |
switch(_orn){ | |
case 'portrait-primary': | |
case 'portrait-secondary': | |
break; | |
case 'landscape-primary': | |
console.log('This is the laptop/desktop version') | |
break; | |
case 'landscape-secondary': | |
break; | |
case undefined: | |
//not supported | |
break; | |
default: | |
//something unknown | |
} | |
return _orn; | |
} | |
window.addEventListener('orientationchange', (ev)=>{ | |
orn = getOrientation(); | |
out.textContent = orn; | |
console.dir(ev) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stupid question but I'm trying to use this in a ReactJS app and it seems to trigger an error:
Do you know what happens to be the issue here?