2

In JavaScript, is it possible to return a value from a parent function from within a jquery callback function?

function thingsLoaded() {
 $("#loadingSplash").fadeOut( 1000, function() { //return thingsLoaded here    });
}

I've read some questions on here regarding Async vs Sync for AJAX callbacks? Does the same apply for this?

Also, I do not need to pass any variables, it's more just a timing thing to return from the thingsLoaded function once the fadeOut is completed.

EDIT: Clarification: I would like to delay returning from the thingsLoaded function, until the fadeOut callback function is complete.

Phrogz
  • 296,393
  • 112
  • 651
  • 745
Dave Chenell
  • 601
  • 1
  • 8
  • 23
  • 2
    you want to return the **thingsLoaded** from the fadeOut's callback or do you want to return the **value of thingsLoaded**? It's rather confusing...can you make the question clearer? – Parth Thakkar May 17 '12 at 14:47
  • What do you want to do? Returning from the `fadeOut` callback won't do anything. – gen_Eric May 17 '12 at 14:48
  • 1
    See this: http://stackoverflow.com/questions/1594077/jquery-synchronous-animation – Zachary May 17 '12 at 15:00

1 Answers1

3

Assuming I've understood your question correctly, (I think you want to return from thingsLoaded in the callback, rather than actually returning thingsLoaded itself) then no.

The thingsLoaded function will return undefined before the callback is executed. If you have code that is dependent on the animation being finished, it has to go inside the callback. This is because fadeOut is asynchronous.

James Allardice
  • 164,175
  • 21
  • 332
  • 312