watch-size
Watch the size changes of a DOM element
Last updated 8 years ago by jonathantneal .
CC0-1.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install watch-size 
SYNC missed versions from official npm registry.

Watch Size PostCSS

NPM Version Build Status Support Chat

Watch Size lets you watch the size changes of a DOM element using the watchSize function.

Usage

Add Watch Size to your project:

npm install watch-size

Use watchSize() to rewrite your queries:

import watchSize from 'watch-size';

const stop = watchSize(
  document.querySelector('.box:nth-child(2)')
  ({ width, height }) => { /* callback */ }
);

/* use stop() to end listening */

How does it work?

The watchSize function attaches hidden, over-sized DOM elements to your target with scroll listeners that are triggered whenever the element resizes. This allows the listener to avoid polling, and to truly respond to size changes. This technique can be used in all browsers going back to Internet Explorer 9.

The entire script is about 400 bytes when minified and gzipped.

Current Tags

  • 2.0.0                                ...           latest (8 years ago)

2 Versions

  • 2.0.0                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (9)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |