Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Need Function to Complete before Proceeding

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #39070
    dman777
    Member

    Have a function called home. And well, obvious what is and what it does.

    function home() {

    fadeTo(white);

    proceed on to other code in the function….

    }

    I have a fade to white effect that I call with function fadeTo(white). Problem is I need the code to wait until this function is complete before proceeding. How can I do this? I considered a callback function but that would mean after the outer function is done run the inner function, which does not work for me in this. I rather not use a timer.

    #106805
    TheDoc
    Member

    Why can’t you use a callback on the fadeTo?

    fadeTo(white, function() {
    // other stuff
    });

    From the docs:
    .fadeTo( duration, opacity [, easing] [, callback] )

    #106806
    TheDoc
    Member

    I’m not sure what ‘white’ is in this case, either.

    #106807
    dman777
    Member

    Since I have a function called home() when the user presses the home() button, I would rather keep to that convention rather than replaced home with fadeTo. I wrote the fadeTo function myself, so I could rewrite the function if I had for it to be called first. For experimenting, I tried placing home() as a callback in fadeTo and called from home(), in which I got a error to much recursive.

    #106834
    TheDoc
    Member

    Well, for starters I would suggest not creating your own function that has the exact same name as one that jQuery uses itself.

    If you wrote fadeTo() yourself, I would just add in a callback for it. This will give you a good start: http://stackoverflow.com/questions/1031674/how-do-i-write-a-jquery-function-that-accepts-a-callback-as-a-parameter

    I’d also change the name of the function ;)

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.