Forums

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?

#169891
dyr
Participant

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 http://modernizr.com/docs/. <- scroll down to near the bottom, look for Modernizr.mq().

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.