Created
November 3, 2013 18:00
-
-
Save ingozoell/7292930 to your computer and use it in GitHub Desktop.
Mobile Detection via CSS/jQuery
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
#mobile-detection { position: relative; display: none; z-index: 0; } | |
@media only screen and (max-width: 600px) { | |
#mobile-detection { position: relative; display: none; z-index: -1;} | |
#page {top:10px; } | |
} |
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
<body> | |
<div id="mobile-detection"></div> | |
... | |
</body> |
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
var $is_mobile = false; // Global var | |
if( $('#mobile-detection').css('z-index') == '-1' ) { | |
$is_mobile = true; | |
} | |
$(document).ready(function() { | |
if($is_mobile) { | |
// Code here ... | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment