I am quite puzzled and still unsure how to explain this in proper words. So far i\'ve used and set up my media queries with Breakpoint. An used Breakpoint-variable looks lik
Similar to @Snugugs's answer but worked better for my use case:
CSS (Note I am using LESS so @tabletMin and @desktopMin translate to breakpoint variables I have set elsewhere:
#cssWidth {
display:none;
content:'mobile';
}
/* Responsive styles (Tablet) */
@media (min-width: @tabletMin) {
#cssWidth {
content:'tablet';
}
/* Other tablet CSS... */
}
/* Responsive styles (Desktop) */
@media (min-width: @desktopMin) {
#cssWidth {
content:'desktop';
}
/* Other Desktop CSS... */
}
And then in JS:
getView = function() {
// If #cssWidth element does not exist, create it and prepend it do body
if ($('#cssWidth').length === 0) {
$('body').prepend($(document.createElement('div')).attr('id', 'cssWidth'));
}
// Return the value of the elements 'content' property
return $('#cssWidth').css('content');
};
The getView() function will then return the string 'mobile', 'tablet' or 'desktop' dependant on the width the media queries see.
This could be extended to fit more viewport widths, just add more rules in the CSS with other values.