Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rejas/mediaquery-event

Get events when mediaquery changes happen
https://github.com/rejas/mediaquery-event

es6 mediaquery vanilla-javascript

Last synced: 10 days ago
JSON representation

Get events when mediaquery changes happen

Awesome Lists containing this project

README

        

# mediaquery-event

Get events when mediaquery changes happen. written in plain vanilla js.

## example

```
document.addEventListener('mediaquery', function (event) {

if (!event.detail.active) {
return; // dont react to mediaqueries becoming inactive
}

if (event.detail.media === 'desktop') {
// do something
}

if (event.detail.media === 'mobile') {
// do something else
}
});

mqe.init({
mediaqueries: [
{name: 'mobile', media: 'screen and (max-width: 1023px)'},
{name: 'desktop', media: 'screen and (min-width: 1024px)'}
]
});
```

## bugs and caveats

Good ol' InternetExplorer handles some stuff differently (no kiddin'), not all of
[these "issues"](http://www.javascriptkit.com/dhtmltutors/cssmediaqueries4.shtml) are handled yet:
- Your mediaquery.media should start with "screen and", otherwise IE adds its own idea to it.