I have a jquery function which loads more post when user scroll below every time
here is the jquery code
$(function() {
var $timeline = $('#tupdate'),
$spinner = $('#loading').hide();
function loadMore() {
$(window).unbind('scroll.posts');
$spinner.show();
$.ajax({
url: "/ajax/loadmore?lastPost=" + $(".pointer:last").attr('id'),
success: function(html) {
if (html) {
$timeline.append(html);
$spinner.hide();
} else {
$spinner.hide();
bootbox.alert('No more post available');
}
$(window).bind('scroll.posts', scrollEvent);
}
});
}
//lastAddedLiveFunc();
$(window).bind('scroll.posts', scrollEvent);
function scrollEvent() {
var wintop = $(window).scrollTop(),
docheight = $(document).height(),
winheight = $(window).height();
var scrolltrigger = 0.95;
if ((wintop / (docheight - winheight)) > scrolltrigger) loadMore();
}
});
Now the problem is whenever user scroll down popup is shown everytime which irritates the user, how can i alert only once?
here is what I've tried
if (!g) {
var g = 1;
bootbox.alert('No more Post');
}
but still it keeps on showing alert every time i scoll down