Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pure javascript div resize event [closed]

I need you because I need to detect if a div is resizing and I just found some solution using JQuery and window.resize.

The thing is that I don't want to use any library, and the window is not resizing. The div is resizing because a menu pop up. I could do that with a dispatch event on the menu, but I want my widget to work itself.

JS FIDDLE : http://jsfiddle.net/b7mNU/3/

I want to get the onresize of the red rectangle without using the event on the menu (yellow div). Something like :

child.addEventListener('resize', function(){ /* do something */ }, false);
like image 943
FlorianB Avatar asked Aug 12 '13 10:08

FlorianB


People also ask

How does Div know resize?

The height and width of the element to be tracked is found out using the height() and width() method in jQuery.

What happen when window is resized?

The resize event fires when the document view (window) has been resized. This event is not cancelable and does not bubble. In some earlier browsers it was possible to register resize event handlers on any HTML element.


1 Answers

These is no such event for <div> elements. You could however use an interval function to watch the state of it's style.width and style.height. If that changes fire a callback.

like image 82
Bart Avatar answered Sep 28 '22 00:09

Bart