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();
};
我初始化我的无限滚动,然后滚动我调用loadMore,在这个函数中我试图关闭无限滚动但这没有效果 - 我哪里出错?
答案 0 :(得分:0)
您需要继续参考“绑定”功能
var myFunc = this.infiniteScroll.bind(this);
p.initInfiniteScroll = function(){
$(window).on('scroll', myFunc);
};
p.terminateInfiniteScroll = function(){
$(window).off('scroll', myFunc);
};