I want to call my code when the width of the block I listen to changes. How to?
onresize
is invoked only when the size of the window changes.
An option can be to use ResizeObserver:
Observes all width changes, wen when MutationObserver
doesn't as in Useless Code's answer.
Does not have much browser compatibility, however.
JS:
var foo = document.getElementById('foo');
var observer = new window.ResizeObserver(entries =>
console.log(entries[0].contentRect.width));
observer.observe(foo);
}
Stackblitz in Angular