The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Media Queries for JS? Reply To: Media Queries for JS?


There are two easy ways to accomplish this.

Set a property in your CSS at whichever breakpoints you need and read that property in your javascript to determine which breakpoint you’re in.

OR use modernizr <- scroll down to near the bottom, look for

Modernizr has a mq() method which takes a media-query like you would write it in css and returns true or false based on whether that media query applies to the current view. I’ve used this before to handle logic which differs on small and large screens and it worked great.