Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

watch-size

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

watch-size

Watch the size changes of a DOM element

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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.

Keywords

FAQs

Package last updated on 24 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc