Created
July 1, 2014 12:33
-
-
Save usaphp/42133e78aa5f8f760a3f to your computer and use it in GitHub Desktop.
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: | |
<div class="display-type"></div> | |
// CSS: | |
// set the content of an element depending on the media query | |
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { | |
.display-type { | |
content: "tablet"; | |
} | |
} | |
@media (max-width: @screen-xs-max) { | |
.display-type { | |
content: "phone"; | |
} | |
} | |
// JAVASCRIPT | |
if($('.display-type').css('content') == "tablet"){ | |
// Actions for tablets | |
} | |
if($('.display-type').css('content') == "phone"){ | |
// Actions for smartphones | |
} |
@murum I'm afraid your code does not have any DOM access improvements. You should consider saving the element in a variable. :) Also, debounce your resize handler.
My 0.02
Awesome technique!
Jeremy Keith wrote a bit about this technique too, back in the day
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I saw jeremenicheills comment and why not work with the code something like this? I think it is slightly more structured, little bit more code but can be used multiple times without doing tons of DOM search for the class display-type etc.