kist-querypoint
Version:
Simple media query breakpoints manager.
136 lines (83 loc) • 2.06 kB
Markdown
Simple media query breakpoints manager.
```sh
npm install kist-querypoint --save
bower install kist-querypoint --save
```
Returns: `Query`
Type: `String`
Breakpoint name.
Type: `String`
Valid `matchMedia` query for resolving.
Returns: `Object` (querypoint)
Type: `String`
Name of breakpoint to remove.
Returns: `Query`
Type: `String`
Name of breakpoint to get.
Returns: `Query`
Type: `Function`
Callback to call when media query enters/exits.
| Argument | Type | Description |
| --- | --- | --- |
| `mq` | `MediaQueryList` | Current media query object. |
Type: `Boolean`
Should you use native media query listener behavior or not (native behavior is to not fire callback on page load, only when exiting/entering query definition).
### `.ignore(cb)`
Returns: `Query`
#### cb
Type: `Function`
Callback to remove from listening.
## Examples
```js
var querypoint = require('kist-querypoint');
// Add querypoint
querypoint.add('bp-alpha-s','screen and (min-width:600px)');
querypoint.add('bp-alpha-m','screen and (min-width:800px)');
querypoint.add('bp-alpha-l','screen and (min-width:1000px)');
// Remove querypoint
querypoint.remove('bp-alpha-s');
// Get querypoint
querypoint.get('bp-alpha-s');
// Listen, even at page load
querypoint
.get('bp-alpha-s')
.listen(function ( mq ) {
if ( mq.matches ) {
// Do something, even at page load
}
});
// Listen, but only with native behavior
querypoint
.get('bp-alpha-s')
.listen(function ( mq ) {
if ( mq.matches ) {
// Do something, but not on page load
}
}, true);
// Unlisten (ignore)
querypoint
.get('bp-alpha-s')
.ignore(cb);
```
```js
define(['kist-querypoint'], cb);
window.kist.querypoint;
```
Tested in IE8+ and all modern browsers.
MIT © [Ivan Nikolić](http://ivannikolic.com)