felipe.zkn
felipe.zkn

Reputation: 2060

jQuery - wait until function execution is complete

Given the following code:

$(classeDoFlipContainer).css('z-index', '1');
$(classeOpostaDoFlipContainer).css('z-index', '0');

flipBox.flippy({
    color_target: "white",
    duration: "900",
    verso: versoDaImagem,
    direction: "BOTTOM",
    onFinish: setEventHandlers,
    onReverseFinish: setEventHandlers
});

alert('?');
$(classeDoFlipContainer).css('z-index', '0');
$(classeOpostaDoFlipContainer).css('z-index', '1');

I added the alert('?'); just to verify that the code after flippy() is being executed. But I need it only when flippy() is completely done. How can I achieve this?

Upvotes: 0

Views: 357

Answers (3)

ignasi
ignasi

Reputation: 443

Using the onFinish callback provided by flippy:

flipBox.flippy({
  color_target: "white",
  duration: "900",
  verso: versoDaImagem,
  direction: "BOTTOM",
  onFinish: function(){
    setEventHandlers();
    alert('?');
    $(classeDoFlipContainer).css('z-index', '0');
    $(classeOpostaDoFlipContainer).css('z-index', '1');
  },
  onReverseFinish: setEventHandlers
});

EDIT: you may also want to add the onReverseFinish callback

Upvotes: 4

Davor Mlinaric
Davor Mlinaric

Reputation: 2017

you can do it like this:

onFinish:function()
{
    alert("yey!");
}

Upvotes: 1

George
George

Reputation: 36786

Use the onFinish callback:

flipBox.flippy({
    color_target: "white",
    duration: "900",
    verso: versoDaImagem,
    direction: "BOTTOM",
    onFinish: function(){
        alert('?');
    },
    onReverseFinish: setEventHandlers
});

Upvotes: 3

Related Questions