Last active
June 2, 2016 15:15
-
-
Save vigneshshanmugam/000632ad4804b769f98d758a509c4802 to your computer and use it in GitHub Desktop.
Check if its Desktop/Mobile without using window.innerWidth
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
<html> | |
<style> | |
@media screen and (max-width: 1024px){ | |
.agent { | |
opacity: 1 !important; | |
} | |
} | |
.agent { | |
opacity: 0; | |
} | |
</style> | |
<script> | |
var isDesktop = true; | |
var agent = document.querySelector('.agent'); | |
var agentValue = window.getComputedStyle(agent); | |
var result = document.querySelector('.result'); | |
function checkDesktop() { | |
if (agentValue.opacity === '1') { | |
isDesktop = false; | |
} else { | |
isDesktop = true; | |
} | |
result.innerHTML = 'Desktop - ' + isDesktop; | |
console.log('Desktop', isDesktop); | |
} | |
window.addEventListener('resize', () => { | |
checkDesktop(); | |
}); | |
checkDesktop(); | |
</script> | |
<body> | |
<div class="agent"></div> | |
<h3 class="result"></h3> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment