JoshBarr / on-media-query

A neat way to trigger JS when media queries change. No jQuery required.
283 stars 33 forks source link

Thoughts on having a * catch all context? #23

Open xzyfer opened 11 years ago

xzyfer commented 11 years ago

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

lukasoppermann commented 10 years ago

Why can't you just do a query with all your mediaqueries

{
    context: ['mobile', 'skinny', 'desktop'],
    match: function() {
        ...
    },
    unmatch: function() {
        ...
    }
}
xzyfer commented 10 years ago

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.

lukasoppermann commented 10 years ago

Ahh, okay, I see.