Skip to content

Instantly share code, notes, and snippets.

@GavinJoyce
Created May 8, 2019 12:24
Show Gist options
  • Save GavinJoyce/079b1f9f6486edfcf4a05774adbafca0 to your computer and use it in GitHub Desktop.
Save GavinJoyce/079b1f9f6486edfcf4a05774adbafca0 to your computer and use it in GitHub Desktop.
import functionalModifier from "ember-functional-modifiers";
import ResizeObserver from "resize-observer-polyfill";
export function onResize(element, [action]) {
let resizeObserver = new ResizeObserver(entries => {
let entry = entries[0];
if (entry) {
let rectangle = entry.contentRect;
let data = {
left: rectangle.left,
right: rectangle.right,
top: rectangle.top,
bottom: rectangle.bottom,
width: rectangle.width,
height: rectangle.height,
x: rectangle.x,
y: rectangle.y,
};
action(data);
}
});
resizeObserver.observe(element);
return () => {
resizeObserver.unobserve(element);
};
}
export default functionalModifier(onResize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment