1

Possible Duplicate:
Detecting when a div's height changes using jQuery
jQuery: Get height of hidden element in jQuery

Is there a way to detect the completion of a fadeIn event with jQuery so I can fire a function on completion?

I understand fadeIn has a built in callback function but this requires me to directly affect the fadeIn code. I don't have access to that code so I want to add an event listener or something to detect when an item has faded in.

The reason I want to do this is because I have some code that detects the height of a div, but on pageload this div element is hidden. I want to detect the height of the div after it is faded in.

Community
  • 1
  • 1
Antonio Moore
  • 930
  • 4
  • 14
  • 21

1 Answers1

-1

You could utilise the DOMAttrModified event, although this will depend on the browsers you need to support as it's still quite experimental.

But since jQuery's animate() changes the style attribute of element(s), it's suitable.

//your code
var div = $('#some_div'), target_height = 100;
div.on('DOMAttrModified', function(evt) {
    if ($(this).height() == target_height) do_something();
});

//some code in another, untouchable script
$('#some_div').animate({height: 100});
Mitya
  • 33,629
  • 9
  • 60
  • 107