
My first post!
Lorem ipsum dolor sit amet consectetur, adipisicing elit...
A responsive element queries library based on modern ResizeObserver technology.
npm install element-queries!npm
!GitHub issues
!npm
!GitHub stars
A modern approach to element queries using a ResizeObserver instead of relying on polling or user-interactions.
- Performant: No polling/loops due to native ResizeObserver use
- Small: under 2kb (minified + gzip)
- Easy to use: doesn't introduce new syntax + simple API
- Customizable: change naming conventions to your liking
This readme reflects the functionality of the current major version (1.x.x)
#### Browser Support
Due to ResizeObserver, Internet Explorer is not supported at all.
You can use a polyfill but I cannot guarantee anything.
More specific information will come soon.
Using NPM / Yarn
Use your favourite package manager to install element-queries.
``bash
$ npm install --save element-queries
$ yarn add element-queries
`
Via script tag
You will find UMD bundles under the dist/ directory. You can download the minified code and include it in your website's
.
Also available via:
jsDelivr: https://cdn.jsdelivr.net/npm/element-queries@latest/dist/element-queries.min.js (
ElementQueries will be available under the window object)Usage
Using Element Queries is easy, you can get going in three steps.
1. First, start out by defining breakpoints on your HTML elements:
`html

My first post!
Lorem ipsum dolor sit amet consectetur, adipisicing elit...
...
...
...
`2. Set up your breakpoints in your stylesheets. Your elements will be given a
data-eq-active attribute, which you can match with CSS selectors.`css
.post[data-eq-active="small"] h2 {
font-size: .75rem;
}.post[data-eq-active="medium"] h2 {
font-size: 1rem;
}
/ breakpoints based on element height /
.post[data-eq-height-active="large"] h2 {
font-size: 1.5rem;
}
/ You can change the attribute name via options /
.post[data-active-bp="large"] h2 {
font-size: 1.5rem;
}
`3. Finally, create an instance of Element Queries in your JavaScript code and let the magic begin. You can also pass custom options via an object.
`js
import ElementQueries from 'element-queries' // if using a package managerconst eq = new ElementQueries()
// ...or pass in custom options
const eq = new ElementQueries({
htmlAttrBreakpoints: 'data-eq-bps',
htmlAttrActive: 'data-active-breakpoint',
// full list below...
})
`That's it! You are now using element queries on your website, now go make it look pretty!
FAQ
#### My elements are added dynamically/after page load (ie. framework), will this pick them up?
Element Queries will detect these automatically as they are added and observe them as long as they have valid breakpoints.
You can also turn this off and write your own wrapper by using the
.watch() and .unwatch() methods.#### What type of elements can I put breakpoints on?
The library technically supports all elements the
ResizeObserver can watch. This means HTMLElements and SVGElements (path, rect, etc.. - not the