24 ways to impress your friends

Jump to menu

Vote up?

James Wragg

The view condition on which this code runs is undoubtedly simple & good for this example, but anything more complicated and it may be more useful to use window.matchMedia which allows you to test @media rules (inc. pixel-ratio, orientation etc.) from your Javascript.

A polyfill is also available in matchMedia.js.