Michael Lynch
Michael Lynch

Reputation: 1743

Div Resize Event not working

I have a tree that expands and collapses, whenever the container div changes sizes i want to do some other stuff, however the .resize() doesn't seem to be working as i wish.

I have the code posted on jsfiddle below:

http://jsfiddle.net/2nXtu/

Thanks

Upvotes: 1

Views: 2996

Answers (2)

rodu
rodu

Reputation: 2358

One way I did this is using a dirty-checking technique.

Basically you check the size of the div you want to monitor the first time, then register a function that runs on a specified interval (say 500ms) and checks for the div size again. If the size has changed from the one you had before you trig some event or run some function and store the new size. It works well if you create efficient closures around your variables.

Upvotes: 0

Purag
Purag

Reputation: 17061

resize() is an event for the resizing of the browser window.

Just put the status updater inside the duplication click event:

$('.dup').live('click', function(){
    var clone = $(this).clone();
    $(this).parent().append( clone );
    $('.height').html( $('.content-body').height() );
    $('.status').html('Resizing');
});

Here it is in action.

Upvotes: 3

Related Questions