我在滚动上调用一个函数,当我达到我的目的时,我正在取消绑定滚动。但是在单击菜单选项卡时我想再次绑定滚动。我们不能在取消绑定后重新绑定滚动而不刷新页面。这是我的代码。
var currentPage = 1;
var xhr = null;
var flag = 0;
(window).bind('scroll');
$(document).ready(function()
{
$('#gallery').bind("click",function()
{
flag = 0;
currentPage = 1;
alert(currentPage);
scroll()
});
});
function scroll(){ $(window).bind('scroll');}
function refresh(){flag = 1; alert("flag");}
function checkScroll() {
if (flag==1){ $(window).unbind('scroll');}
if(nearBottomOfPage() == 0)
{
currentPage ++;
xhr = $.ajax(
{
url : '/ideabank?page=' + currentPage,
beforeSend: function() {
$('#loading').show()
},
complete: function(){
$('#loading').hide()
},
success : function(){}
} );
}
}
function nearBottomOfPage() {
return scrollDistanceFromBottom();
}
function scrollDistanceFromBottom(argument) {
return $(document).height() - ($(window).height() + $(window).scrollTop());
}
$(window).bind('scroll',function (){
checkScroll();
});