发布于 2015-08-18 16:34:28 | 231 次阅读 | 评论: 0 | 来源: 网络整理
当从一个页面跳转到另外一个页面时,页面滚动条总是停留在同样的位置。例如,如果访问了一个显示了很长列表的页面,并且滚动到页面的底部,这时又切换到另外一个具有长列表的页面,会发现页面的滚动条位置并没有被重置。
添加下面的Mixin到受影响的路由:
1 2 3 4 5 6 |
App.ResetScroll = Ember.Mixin.create({
activate: function() {
this._super();
window.scrollTo(0,0);
}
});
|
只要想在activate方法中做点什么,就需要在一开始的时候调用this._super():
1 2 3 4 5 6 7 |
App.IndexRoute = Ember.Route.extend(App.ResetScroll, {
//I need to do other things with activate
activate: function() {
this._super.apply(this, arguments); // Call super at the beginning
// Your stuff
}
});
|