ember-on-resize-modifier

2.0.2 • Public • Published

{{on-resize}} modifier

CI status NPM version

{{on-resize}} modifier allows to use ResizeObserver to respond to an element's size changes. It relies on a single ResizeObserver instance to achieve better performance (using multiple instances can result in a noticeable performance penalty).

It has good test coverage and is ready for production👍

Installation

ember install ember-on-resize-modifier

If you need a ResizeObserver polyfill (caniuse.com):

ember install ember-resize-observer-polyfill

Usage

<div {{on-resize callback}} />

The callback will be called:

  • when the element is inserted to the DOM
  • whenever the size of the element changes
  • when element.style.display gets set to none (then all contentRect props will be 0)

The callback will be always called with the only argument wich is ResizeObserverEntry object.

Example

<div {{on-resize this.handleResize}}>
  Resize me
</div>
@action
handleResize({ contentRect: { width, height } }) {
  target.classList.toggle('large', width > 1200);
  target.classList.toggle('portrait', height > width);
}

Related addons

Compatibility

  • Ember.js v3.20 or above
  • Ember CLI v3.20 or above
  • Node.js v12 or above

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i ember-on-resize-modifier

Weekly Downloads

10,845

Version

2.0.2

License

MIT

Unpacked Size

11.7 kB

Total Files

10

Last publish

Collaborators

  • dougestey
  • hasitha-pn
  • lauragonzalezz
  • trianglegrrl
  • pnfinance
  • pn-bot
  • jonhunt-pn
  • christophermilne
  • vpuzzella
  • ivanvotti
  • miguelverissimo
  • pn-ips
  • ghedamat
  • jfh