ember install ember-element-resize-detector
This addon provides a resize-detector
service and a {{resize-detector}}
component.
This component allows you to specify what element should be monitored for change and what action should be triggered.
{{resize-detector '#my-container' on-resize=(action 'resize')}}
<div id="my-container"></div>
jQuery CSS selector for an element that should be watched.
Action to be triggered when resized. The action handler will receive a hash with width
and height
as well as the element that changed sizes.
The service allows you to create components that monitor sizes of other DOM elements. To use the service in you need to inject into the component and add a listener.
To see a complete implementation, look at the {{resize-detector}}
component's code.
The service provides two methods.
Will add a listener that'll trigger the callback when the element matching the selector changes in size.
Selector is jQuery selector that'll match the element. The detector will only watch the first matched element. I would recommend creating callbacks using Ember.run.bind
to ensure that
the runloop is started when the callback is called.
Will remove the listener from element matching selector for given callback.
If it is a bug please open an issue on GitHub.
To use this addon as a dependency of another addon, you must specify this addon as a peerDependency of your addon. This will cause the host app that's installing your addon to also install this addon in the root node_modules. For more formation, read comment in ember-tether library.
This addon uses wnr/element-resize-detector library. Lucas Wiener thank you for doing the hard to work make this performant.