1

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

Michael Lynch
  • 1,743
  • 15
  • 27
  • Error, `GET https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js ` is failing because that link no longer works – SpYk3HH Aug 07 '12 at 17:13
  • 1
    Look at this answer [here](http://stackoverflow.com/a/3797188/586621) for a jQuery plugin that does what you want. – Jay Aug 07 '12 at 17:15
  • @SpYk3HH - what are you talking about? – j08691 Aug 07 '12 at 17:15
  • As a note, use of `.live` is deprecated http://api.jquery.com/live/ , use `$('.content-body').on('click','.dup', function(){})` – Mark Coleman Aug 07 '12 at 17:16
  • @j08691 when i went to his fiddle, it gave me an error on the jquery till i changed it to edge – SpYk3HH Aug 07 '12 at 17:29

2 Answers2

3

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.

Purag
  • 16,941
  • 4
  • 54
  • 75
  • The issue i have with this solution is that i reuse the same layout on multiple locations and don't want to place the code there explicitly. I guess I'll leave the code as i have it, and where-ever i have code that alters the size of the div i will manually call $('.content-body').resize(); (same concept as your answer). – Michael Lynch Aug 07 '12 at 17:33
0

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.

rodu
  • 2,308
  • 3
  • 15
  • 6