salvattore icon indicating copy to clipboard operation
salvattore copied to clipboard

MatchMedia matches only when scaling the window down

Open piffpaffpuff opened this issue 9 years ago • 5 comments

Three media queries: first has 2, the other 3 and the last 4 columns.

While resizing the browser window down the mql.matches is correct. But if you resize it up again mql.matches always returns false. ie: it stays in 2 columns instead of switching to 3.

Tested with latest chrome, safari and firefox

piffpaffpuff avatar Mar 05 '15 20:03 piffpaffpuff

I noticed the same.

fourroses666 avatar Mar 09 '15 14:03 fourroses666

I found out that it works better if your media queries have both, a min-width and max-width.

piffpaffpuff avatar Mar 09 '15 15:03 piffpaffpuff

A workaround I was able to do for this was specifically calling rescanMediaQueries on a window resize. Example using jQuery:

$(window).on('resize', function() {
    salvattore.rescanMediaQueries();
});

vaughnroyko avatar Mar 24 '15 15:03 vaughnroyko

Noticed this too but the above fix worked fine for me.

eheiser avatar Apr 21 '15 18:04 eheiser

To improve the JS performance of the workaround consider wrapping it in a debouncer or done resizing event solution like https://css-tricks.com/snippets/jquery/done-resizing-event/

Soundvessel avatar Dec 17 '15 23:12 Soundvessel