我有一个函数可以监听浏览器的scroll
事件。在此函数中,我检查lastScrollTop
的值是高于还是低于先前的值(存储在st
中)。在Google Chrome浏览器中,这工作得很好,但是在Mozilla Firefox中,这会导致问题。
$(function() {
var commentCount = $('.ItemCount').val(),
nextPageNumber = 2,
lastScrollTop = 0,
pageSize = @Model.Filter.PageSize,
newTab = false,
isFetchingData = false;
$(window).on('scroll',
function () {
var st = $(this).scrollTop();
if (st > lastScrollTop) {
if (newTab) {
commentCount = parseInt($('.ItemCount:first').val()), nextPageNumber = 2, lastScrollTop = 0, pageSize = @Model.Filter.PageSize;
}
if (!isFetchingData && commentCount > 0 && commentCount >= pageSize) {
var scrollBottom = ($(window).scrollTop() + $(window).height()) - ($($('header').children()[0]).height() + $('#footer-new').height() + $('#footer').height() + $('.load-wrapp').height());
var div = $('.commentList');
var bottom = ((div.offset().top + div.height()) - scrollBottom);
if (bottom < 0) {
isFetchingData = true;
var url = $('.comments .nav.nav-tabs li.active a').attr('href')
.replace("CurrentPage=1&", "CurrentPage=" + nextPageNumber + "&");
url = url.replace("&ViewName=Tab", "&ViewName=List");
$.ajax({
url: url,
async: false,
success: function (data) {
$('.commentList').append(data);
commentCount = parseInt($('.ItemCount:last').val());
isFetchingData = false;
nextPageNumber++;
}
});
}
}
else {
$('.load-wrapp').attr('style', 'display:none !important')
}
}
lastScrollTop = st;
newTab = false;
});
$('.nav.nav-tabs li a').on('click',
function () {
newTab = true;
});
})