WickyNilliams / enquire.js

Awesome Media Queries in JavaScript
http://wicky.nillia.ms/enquire.js/
MIT License
3.62k stars 269 forks source link

Only matched is fired, why? #152

Closed JensNielsen81 closed 7 years ago

JensNielsen81 commented 8 years ago

Not sure i am doing this right.

enquire.register("screen and (max-width: 767px)", {
    match : function() {
        var feed = new Instafeed({
            clientId: '237094fcb1b84784b49e93a52f30dc6d',
            accessToken: '3230782367.1677ed0.eb1d8459f00840beb6db38b73eb4b25e',
            get: 'user',
            userId: 3230782367,
            resolution: 'standard_resolution',
            limit: '6'
        });
        feed.run();
    },
    unmatch : function() {
        var feed = new Instafeed({
            clientId: '237094fcb1b84784b49e93a52f30dc6d',
            accessToken: '3230782367.1677ed0.eb1d8459f00840beb6db38b73eb4b25e',
            get: 'user',
            userId: 3230782367,
            resolution: 'standard_resolution',
            limit: '8'
        });
        feed.run();
    }
});`

This only gives me the matched version ie, the mobile one, my page is blank on desktop until it hits 767px width.

WickyNilliams commented 7 years ago

Yes, that's the intended behaviour. The library is meant for progressive enhancement - unmatch only fires, if the query has been previously matched (it's meant for undoing anything you did in match, not to be the else case).

If you want to run code when it doesn't match, you can register a new handler and either: