Yes, you can create a function like this:
var isLarge, isMedium, isSmall; isSmall = function() { return matchMedia(Foundation.media_queries['small']).matches && !matchMedia(Foundation.media_queries.medium).matches; }; isMedium = function() { return matchMedia(Foundation.media_queries['medium']).matches && !matchMedia(Foundation.media_queries.large).matches; }; isLarge = function() { return matchMedia(Foundation.media_queries['large']).matches; };
Then name it like this:
if (isSmall()) { alert("Too small!"); } if (isLarge()) { alert("Too big!"); } if (isMedium()) { alert("Just right!"); }
Another way that is not basic:
In your query for CSS multimedia, just for small (adapt):
@media only screen and (max-width: 40.063em) { body:after { content: 'small'; display: none; } }
In your Javascript, use a function to get the contents of this element and compare it:
var getSize; getSize = function() { return window.getComputedStyle(document.body, ':after').getPropertyValue('content'); };
In some browsers, getSize () will return the value that is being quoted, so using if (getSize () == "small") does not work. You can get around this using this for comparison:
if (getSize().indexOf("small") !== -1) { // do something }
Subscribe to this blog post for this method: http://adactio.com/journal/5429/
source share