Skip to content

Instantly share code, notes, and snippets.

@ingozoell
Created November 3, 2013 18:00
Show Gist options
  • Save ingozoell/7292930 to your computer and use it in GitHub Desktop.
Save ingozoell/7292930 to your computer and use it in GitHub Desktop.
Mobile Detection via CSS/jQuery
#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; }
}
<body>
<div id="mobile-detection"></div>
...
</body>
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