我有一个工作滚动混合(你可以在这个要点中看到)。
App.Scrolling = Em.Mixin.create({
bindScrolling: function() {
var onScroll;
var _this = this;
var scrollFunc = function(){
return _this.scrolled();
};
onScroll = scrollFunc;
$(document).bind('touchmove', onScroll);
$(window).bind('scroll', onScroll);
},
unbindScrolling: function() {
$(window).unbind('scroll');
$(document).unbind('touchmove');
}
});
App.ApplicationView = Ember.View.extend(App.Scrolling, {
didInsertElement: function() {
this.bindScrolling();
},
willRemoveElement: function() {
this.unbindScrolling();
},
scrolled: function() {
console.log('MyView was scrolled : ' + document.body.scrollTop);
}
});
但我相信建议使用 Ember 运行循环(特别是 debounce - http://emberjs.com/api/classes/Ember.run.html#method_debounce )来消除这种情况。
这里的非工作代码示例:
问题代码在这里:
onScroll = Ember.run.debounce(this, scrollFunc, 200);
不幸的是,无论我使用什么上下文,我似乎都无法让它工作。
如果有一些见解,我们将不胜感激。
谢谢
克里斯
最佳答案
如果将 onScroll
分配给一个函数,它将起作用,
onScroll = function(){Ember.run.debounce(this, scrollFunc, 200);};
关于javascript - 使用 Ember.run.debounce 消除滚动滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22158508/