I am calling a function on scroll, when my purpose is served I am unbinding the scroll.But on the click of menu tab I want to bind the scroll again.Cant we re-bind the scroll after unbinding it with out refreshing the page.Here is my code.
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();
});