Created
March 24, 2016 21:00
-
-
Save JeffreyATW/33fd51217d098a9ae90b to your computer and use it in GitHub Desktop.
Use CSS-defined media breakpoints in JS without matchMedia
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
<div class="mq"> | |
<div class="mq__xs"></div> | |
<div class="mq__sm"></div> | |
<div class="mq__md"></div> | |
<div class="mq__lg"></div> | |
</div> |
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
if ($('.mq__xs').is(':visible')) { | |
console.log('xs'); | |
} | |
if ($('.mq__sm').is(':visible')) { | |
console.log('sm'); | |
} | |
if ($('.mq__md').is(':visible')) { | |
console.log('md'); | |
} | |
if ($('.mq__lg').is(':visible')) { | |
console.log('lg'); | |
} |
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
.mq { | |
> * { | |
display: none; | |
} | |
&__xs { | |
@media (max-width: $screen-xs-max) { | |
display: block; | |
} | |
} | |
&__sm { | |
@media (min-width: $screen-sm-min) and (max-width: $screen-sm-max) { | |
display: block; | |
} | |
} | |
&__md { | |
@media (min-width: $screen-md-min) and (max-width: $screen-md-max) { | |
display: block; | |
} | |
} | |
&__lg { | |
@media (min-width: $screen-lg-min) { | |
display: block; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment