在Emberjs破坏之前制作动画

Ted*_*nny 6 ember.js

目前无法延迟Ember中的视野破坏.如果要在销毁视图之前为视图设置动画,则会出现此问题.

所以,我目前有这个非常丑陋的解决方法:

willDestroyElement: ->
  $clone = @$().clone().addClass "animate-destruction"
  @$().parents(':first').prepend $clone
  setTimeout ->
    $clone.off().remove()
  , 350
Run Code Online (Sandbox Code Playgroud)

注意:动画是.animate-destruction在css 中的类中完成的.

我知道我的方法很糟糕,所以我想知道是否有人提出了更好的方法.

mav*_*ein 1

这只是我的一个自发想法:

这是 Ember.View 中 destroyElement 的实现(链接到源代码):

 destroyElement: function() {
    return this.currentState.destroyElement(this);
  },
Run Code Online (Sandbox Code Playgroud)

您可以尝试重写此方法来执行动画:

destroyElement: function() {
    var completeCallback = function(){
        return this.currentState.destroyElement(this);
    }
    this.$().fadeOut(completeCallback); //or whatever animation
},
Run Code Online (Sandbox Code Playgroud)