on-media-query
on-media-query copied to clipboard
Thoughts on having a * catch all context?
This is something we use in our projects. It essentially emulates matchMedia.addListener() but achieves the goal not repeating media queries in js and css.
I've got a proof of concept we're currently using here: https://github.com/xzyfer/js-media-queries/commit/6f1398a62f234ff2ce9f2bbf98c7cb938c1c6785
Why can't you just do a query with all your mediaqueries
{
context: ['mobile', 'skinny', 'desktop'],
match: function() {
...
},
unmatch: function() {
...
}
}
The goal is for the js not to know anything about our media queries. We want to define out contexts in css with the rest of our media query and just have our js fire event/callback when we've transitioned between contexts.
Ahh, okay, I see.