JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://rawgit.com/WickyNilliams/enquire.js/master/dist/enquire.js"></script>
<div class="test test-a"></div>
<div class="test test-b"></div>
CSS
.test {
height: 100px;
border: 1px solid #999;
margin-bottom: 1em;
}
JavaScript
var testA = document.querySelector(".test-a");
var testB = document.querySelector(".test-b");
var testC = document.querySelector(".test-c");
// either use setup
enquire.register("(max-width: 640px)", {
setup : function() {
testA.style.backgroundColor = "blue";
},
match : function() {
testA.style.backgroundColor = "red";
},
unmatch : function() {
testA.style.backgroundColor = "blue";
}
});
// or two mutually exclusive media queries
enquire.register("(max-width: 640px)", {
match : function() {
testB.style.backgroundColor = "red";
}
})
.register("(min-width: 641px)", {
match : function() {
testB.style.backgroundColor = "blue";
}
});