2016-02-15 23 views
1

我需要在dom元素上的动画结束后执行方法。 目前我使用下面的代码没有成功。dojo/_base/fx支持承诺吗?

我想知道如果道场,支持承诺的动画,如果没有,我想知道我能以哪种方式工作。

 fx.fadeOut({ node: 'target'}).play().then(function() { 
      // do smt here 
     }.bind(this)); 

回答

3

是的,你可以使用FadeOut功能的注册回调。

fadeOutdojo/_base/fx函数返回一个annimation实例) 提供5个registred回调函数:

  • beforeBegin
  • onBegin
  • onEnd
  • onPlay
  • onAnimate(带参数)

你的情况,你需要做的时候动画完成一些动作已经过时了在FadOut参数的onEnd功能,它应该看起来像:

fx.fadeOut({ 
    node:"target", 
    onEnd: function(){ 
     // Some stuff at the end of the animation. 
    } 
}).play(); 

你也可以用上面的回调为ARGS。

0

我能解决使用'dojo/on'和订阅到End事件上fx.fadeOut()这个问题。我仍然很有兴趣了解是否有更好的方法来达到同样的结果。

 var anim = fx.fadeOut({ node: 'target'}).play(); 
     on(anim, "End", function() { 
      // dom smt here 
     }.bind(this));