我正在調用滾動功能,當我的目的服務我解除了綁定滾動。但在菜單選項卡的點擊我想再次綁定滾動。我們可以重新綁定滾動後綁定它與刷新頁面。這裏是我的代碼。因爲他們不提供一個處理函數綁定綁定/解除綁定滾動
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();
});
可能重複的[無法重新綁定滾動事件?](http://stackoverflow.com/questions/11122010/can-not-rebind-scroll-event) – 2012-07-11 06:19:56