p.initInfiniteScroll = function(){
$(window).on('scroll', this.infiniteScroll.bind(this));
};
p.terminateInfiniteScroll = function(){
$(window).off('scroll', this.infiniteScroll);
};
p.infiniteScroll = function(){
if($(window).scrollTop() == $(document).height() - $(window).height()){
this.loadMore();
}
};
p.loadMore = function(){
console.log('load more');
this.terminateInfiniteScroll();
};
我init我的无限滚动,然后在滚动时我调用loadMore,在这个函数内,我试图关闭无限滚动,但这没有效果-我在哪里出错?
你需要保持你的"绑定"函数的引用
var myFunc = this.infiniteScroll.bind(this);
p.initInfiniteScroll = function(){
$(window).on('scroll', myFunc);
};
p.terminateInfiniteScroll = function(){
$(window).off('scroll', myFunc);
};