{"id":17961,"date":"2012-09-04T16:08:23","date_gmt":"2012-09-04T23:08:23","guid":{"rendered":"http:\/\/css-tricks.com\/?p=17961"},"modified":"2017-04-13T17:44:39","modified_gmt":"2017-04-14T00:44:39","slug":"enquire-js-media-query-callbacks-in-javascript","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/enquire-js-media-query-callbacks-in-javascript\/","title":{"rendered":"Enquire.js – Media Query Callbacks in JavaScript"},"content":{"rendered":"
The following is a guest post Nick Williams. Nick emailed me about a new library he created to assist in working with responsive design. Specifically, he was implementing an idea he found here on CSS-Tricks but wanted to do so more intelligently by only running the script when needed. Thus the birth of this new mini library! There are some kind of similar<\/a> ones out there, but this one is very small and works with native media queries. I’ll let Nick tell you more about it…<\/div>\n

Enquire.js<\/a> is a JavaScript library I created for dealing with media queries in JavaScript.<\/p>\n

“Whoa! Back it up!<\/em> Media queries in JavaScript?! What kind of abomination is this?”<\/p><\/blockquote>\n

Whilst the premise may seem odd, it really is a handy addition to the responsive toolbox.<\/p>\n

The Lowdown<\/h3>\n

Enquire.js is a lightweight, pure JavaScript library for handling media queries. It is less than 1kb when GZIP’d and minified, and has absolutely no dependencies. Yup, you read that right – no dependencies, not even jQuery! The most you will have to do is provide a matchMedia polyfill<\/a> if you wish to support browsers without a native implementation<\/a>.<\/p>\n

Use Cases<\/h3>\n