有人找到了一种好的方法来实现状态转换动画吗?
路由器会立即将视图从DOM中移除。这个问题在于我无法推迟它直到动画结束。注意:我正在使用 v1.0.0-pre.4。
我知道这个问题很老了,但是今天处理特定上下文动画的最佳解决方案可能是 ember liquid fire。
它可以让你在转换文件中做像这样的事情:
export default function(){
this.transition(
this.fromRoute('people.index'),
this.toRoute('people.detail'),
this.use('toLeft'),
this.reverse('toRight')
);
};
App.CrossfadeView = {
didInsertElement: function(){
//called on creation
this.$().hide().fadeIn(400);
},
willDestroyElement: function(){
//called on destruction
this.$().slideDown(250);
}
};
然后在你的代码中,你可以将它应用于各种视图类。由于Ember依赖于jQuery,因此你几乎可以使用任何jQuery动画。
App.IndexView = Ember.View.extend(App.CrossfadeView);
App.PostView = Ember.View.extend(App.CrossfadeView);
fadeIn
确实有效,但是 willDestroyElement
中的 slideDown
对我来说不可见。 - graup{{#linkTo "todos"}}<button>Todos</button>{{/linkTo}}
<a href="#/todos" {{action "goToTodos"}}><button>Todos</button></a>
在当前控制器中创建goToTodos方法
App.IndexController = Ember.Controller.extend({
goToTodos: function(){
// Get Current 'this' (for lack of a better solution, as it's late)
var holdThis = this;
// Do Element Specific Animation Here
$('#something').hide(500, function(){
// Transition to New Template
holdThis.transitionToRoute('todos');
});
}
});
App.TodosView = Ember.View.extend({
didInsertElement: function(){
// Hide Everything
this.$().hide();
// Do Element Specific Animations Here
$('#something_else').fadeIn(500);
}
});
到目前为止,这是我发现的在过渡中针对特定元素进行动画的最优雅的解决方案。如果有更好的,非常愿意听取!
App.ExampleView = Ember.View.extend({
willAnimateIn : function () {
this.$().css("opacity", 0);
},
animateIn : function (done) {
this.$().fadeTo(500, 1, done);
},
animateOut : function (done) {
this.$().fadeTo(500, 0, done);
}
}
App.SomeView = Ember.View.extend({
didInsertElement: function(){
//called on creation
this.$().hide().fadeIn(400);
},
willDestroyElement: function(){
//called on destruction
this.$().slideDown(250)
}
});
Ember.View#willDestroyElement
将过渡类添加到你的视图中? - MilkyWayJoe