Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  125] [ 6]  / answers: 1 / hits: 18705  / 6 Years ago, sun, march 25, 2018, 12:00:00

Take a look at this example: https://jsfiddle.net/vxun2Lgg/2/


I've attached an "resize" event listener on container div. After opening up dev tools, and modifying the width of container, resize callback does not get called. What am I missing?


PS:
I am not interested in window resize event, only in container div.




var container = document.getElementsByClassName(container)[0];
container.addEventListener(resize, function() {
console.log(resizing)
});

<div class=container></div>




More From » html

 Answers
37

resize is only valid for the window. If supported you can use ResizeObserver.



new ResizeObserver(() => console.log(resizing)).observe(container);


Otherwise, you will probably have to poll using setInterval and check the size.


[#54863] Wednesday, March 21, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jimmieo

Total Points: 515
Total Questions: 102
Total Answers: 110

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
;