Wednesday, August 26, 2015

Introducing enquire.js

For some time now, I’ve been using the enquire.js library to augment the use of media queries in JavaScript. I’ve had a lot of success using the library in various projects, but most developers I’ve met confessed they’ve never used or even heard of it.

In this article, I want to introduce you the library, explain why and how you’d want to use it.

What is enquire.js?

enquire.js is a lightweight, pure JavaScript library for responding to CSS media queries. In my own words, enquire.js gives you additional functionality and flexibility on top of window.matchMedia() when working with media queries in JavaScript.

The library was written by Nick Williams and it’s been around for about three years, having a healthy amount of open source activity. Its aim is not to replace or polyfill matchMedia; rather, it exists to provide additional functionality around media queries that don’t exist natively.

Why Would I Use It?

There are lots of use cases where enquire.js could be used, including:

  • Move nodes around the DOM
  • Load supplementary content (e.g. ads) via Ajax
  • Load and run a JavaScript library (e.g. Packery) to enhance a page

Each of these use cases is covered in the following sections.

Continue reading %Introducing enquire.js%


by Damon Bauer via SitePoint

No comments:

Post a Comment