Is there a way for Javascript to detect when a specific CSS media query is active without repeating the conditions of the media query in Javascript? Perhaps something similar to an HTML data attribute, but for CSS.
For example:
CSS
@media (min-width: 94em) {
.menu{
-data-break: sidebar-open;
}
}
Javascript
if( $('.menu').cssData('break') == 'sidebar-open' ){
...
}
I want a side drawer to automatically open when the window reaches a certain width and a specific media query is activated.
I understand I could achieve this by checking the window's width in Javascript, but I'm looking for a solution that doesn't involve duplicating the width variable. Additionally, I am aware that I could make the Javascript code dependent on the CSS rules inside the media query, but that wouldn't be practical in this scenario.