jQuery - 等到函数执行完成

时间:2013-08-09 10:37:15

标签: jquery

给出以下代码:

$(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');

我添加alert('?');只是为了验证flippy()之后的代码是否正在执行。但我只有在完成flippy()时才需要它。我怎样才能做到这一点?

3 个答案:

答案 0 :(得分:4)

使用flippy提供的onFinish回调:

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
});

编辑:您可能还想添加onReverseFinish回调

答案 1 :(得分:3)

使用onFinish回调:

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

答案 2 :(得分:1)

你可以这样做:

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