Script to add a MatchMedia event for each media query in a page's stylesheets
This small script:
The mqEvents function is attached to the window object, which it probably should not be.
Run mqEvents()
.
Pass it a single function parameter that will run each time a MatchMedia event fires. The function will be passed the MediaQueryList from the event.
mqEvents(function (mql) {
if (mql.matches) {
// Media query condition was met
}
else {
// Media query condition was not met
}
});