My method fades a div box out and has a callback that calls a method... like this:
function closeWindow(windowIdPrefix, speed) {
$("#" + windowIdPrefix + "_ViewPanel").fadeOut(speed,
function() {
resetWindow(windowIdPrefix);
numWindowsOpen--;
}
);
}
function resetWindow(windowIdPrefix) {
alert("resetting window");
}
When this executes (onClick of a button) I have an alert in resetWindow to see how many times it executes.
It seems to execute forever, but I haven't sat there long enough closing the alert windows to find out.
I did some research and read in the Jquery Documentation:
callback (Optional) Function A function to be executed whenever the animation completes, executes once for each element animated against.
So I was wondering, even though I'm only fading out 1 div, does it count as 1.. plus 1 for each child element the div has?
Technically they are being animated because the inner elements are being faded out with the outer div, but if you watch the javascript in firebug only the outer div I'm fading out gets it's opacity/display changed.
If this is what's happening, how do I make sure the callback only gets executed once?
Edit: It was the line numWindowsOpen--;
I hadn't defined numWindowsOpen before the function so for some reason that was making the call happen multiple times... Can anyone explain why this was happening?