Created
August 8, 2012 14:55
-
-
Save jordanmoore/3295630 to your computer and use it in GitHub Desktop.
Context-based loading JavaScript using CSS media query breakpoints
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
<script type="text/javascript"> | |
var LegacyIE = { | |
Version: function() { | |
var version = 999; | |
if (navigator.appVersion.indexOf("MSIE") != -1) | |
version = parseFloat(navigator.appVersion.split("MSIE")[1]); | |
return version; | |
} | |
} | |
if (LegacyIE.Version() <= 8) { | |
// Do something only in large contexts (and if the browser doesn't recognise CSS :after) | |
} else { | |
var size = window.getComputedStyle(document.body,':after').getPropertyValue('content'); | |
if (size.indexOf("small") !=-1) { | |
// Do something only in small contexts | |
} | |
if (size.indexOf("medium") !=-1) { | |
// Do something only in medium contexts | |
} | |
if (size.indexOf("large") !=-1) { | |
// Do something only in large contexts | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment