Skip to content

Instantly share code, notes, and snippets.

@schmidt1024
Last active August 29, 2015 14:15
Show Gist options
  • Save schmidt1024/c8f1639b81ba7c0a1ddc to your computer and use it in GitHub Desktop.
Save schmidt1024/c8f1639b81ba7c0a1ddc to your computer and use it in GitHub Desktop.
jQuery media query like css
<div id="smartphone">Smartphone</div>
<div id="tablett">Tablett</div>
<div id="desktop">Desktop</div>
$( document ).ready(function() {
var is_smartphone = false;
var is_tablett = false;
var is_desktop = false;
if( $('#smartphone').css('display')=='block') {
is_smartphone = true;
}
if( $('#tablett').css('display')=='block') {
is_tablett = true;
}
if( $('#desktop').css('display')=='block') {
is_desktop = true;
}
if (is_smartphone == true) {
// your script here
}
if (is_tablett == true) {
// your script here
}
if (is_desktop == true) {
// your script here
}
});
#smartphone {
display: block;
}
#tablett {
display: none;
}
#desktop {
display: none;
}
@media screen and (min-width: 768px) {
#smartphone {
display: none;
}
#tablett {
display: block;
}
#desktop {
display: none;
}
}
@media screen and (min-width: 992px) {
#smartphone {
display: none;
}
#tablett {
display: none;
}
#desktop {
display: block;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment