Every View
在 ember 中有一个名为didInsertElement
:
当视图元素插入到 DOM 中时调用。
重写此函数以执行任何需要元素的设置
文档正文。
所有 ember 视图还有一个$
这是对 jQuery 的引用,因此您可以用它包装视图中的某些元素并对其应用任何更改,例如:
// this will animate only the tag h2, which in your case is the title of the users view
App.UsersView = Ember.View.extend({
templateName: 'users',
didInsertElement: function() {
this.$('h2').animate({ fontSize: "3em" }, 900 );
}
});
或者您可以不带参数调用它(例如$()
) 返回由 jQuery 包装的当前视图。
要在您进入该视图/路线时对视图进行动画处理,请在您的App.UsersView
:
// this will animate the entire view
App.UsersView = Ember.View.extend({
templateName: 'users',
didInsertElement: function() {
this.$().animate({ fontSize: "3em" }, 900 );
}
});
(Note:我的动画非常蹩脚,但这只是为了显示在哪里调用方法,做一个真正的动画)
这是一个修改版本你的 JSBin http://jsbin.com/ehafoh/2/edit#javascript,html