In a post made almost a year ago, user Iminay asked for help forcing jQuery to wait for a fade event to complete before initiating the next action:
http://groups.google.com/group/jquery-en/browse_thread/thread/bbe0471b780e666a After two helpful posts, it seems that his problem was solved. Unfortunately, I'm not able to replicate his success with either of the posted solutions so I'm asking for some clarification and some assistance. In essence, I've got the following chunk of code that rotates images through a jQuery-based JavaScript image rotator. function show_next_rotating_item(t) { jQuery(t).fadeOut(2000); var next_rotating_item = jQuery(t).siblings('.rotating_item:random'); if(!next_rotating_item.attr('class')) { next_rotating_item = jQuery('#rotating_items div.rotating_item:first'); } //Pause for a user specified amount of time - say 3000 milliseconds? next_rotating_item.fadeIn(1000); showing = next_rotating_item; } As you can see, it's super simple. In other parts of the code not posted for sake of brevity, this function is called by setInterval() with a delay of 5000 milliseconds. How can I force jQuery to pause (in this instance, it pauses with a white background) for a specified time before moving on to the FadeIn() function? In most other languages I know, there's almost always been a sleep(), wait(), pause(), delay(), etc. function or method, but the only one I seem able to find is setTimeout() which, unfortunately doesn't give the desired effect. From my modest experience with JavaScript coding, setTimeout() seems to spin off the delayed execution of a function into another separate process or something, and then continues executing code right where it left off. The delay happens in parallel to the execution of the remainder of the code that follows the setTimeout() function. Unfortunately, this behavior isn't what I'm looking for. How might I achieve a more... serial... behavior? I know the responses that David McFarland and Karl Swedberg gave in their responses to Iminay's original post dealt with something called 'callbacks', but I wasn't able to decipher their code... Could someone provide a solution that's less complex than theirs? Perhaps something that's much more human/programmer-readable, even if it's at the cost of length and code size? -WH