|
3 年之前 | |
---|---|---|
.. | ||
CHANGELOG.md | 3 年之前 | |
LICENSE.md | 3 年之前 | |
README.md | 3 年之前 | |
index.cjs.js | 3 年之前 | |
index.es.mjs | 3 年之前 | |
package.json | 3 年之前 |
Watch Size lets you watch the size changes of a DOM element using the
watchSize
function.
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 */
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.