您好我遇到了无限滚动功能的问题,当所有内容都显示出来时,它仍然继续滚动(奇怪的行为)。我正在寻找一种在显示所有内容时停止无限滚动的方法......但首先我需要知道何时没有更多页面/内容
这是我的代码
<script type="text/javascript">
jQuery(document).ready(function ($) {
(function () {
var page = 1,
loading = false,
finish = false;
function nearBottomOfPage() {
return $(window).scrollTop() > $(document).height() - $(window).height() - 200;
}
function finish() {
finish = true;
}
$(window).scroll(function () {
if (loading) {
return;
}
if (nearBottomOfPage() && !finish) {
loading = true;
$('#loader').show();
page++;
$.ajax({
url: '/office?page=' + page,
type: 'get',
dataType: 'script',
success: function () {
$('#loader').hide();
loading = false;
}
});
}
});
}());
我试过这个
<script type="text/javascript">
jQuery(document).ready(function ($) {
(function () {
var page = 1,
loading = false,
finish = false;
function nearBottomOfPage() {
return $(window).scrollTop() > $(document).height() - $(window).height() - 200;
}
function finish() {
finish = true;
}
$(window).scroll(function () {
if (loading) {
return;
}
if (nearBottomOfPage() && !finish) {
loading = true;
$('#loader').show();
page++;
$.ajax({
url: '/office?page=' + page,
type: 'get',
dataType: 'script',
success: function () {
$('#loader').hide();
loading = false;
}
});
$.error(function(jqXHR, textStatus, errorThrown) {
//Finish scrolling.
finish();
});
}
});
}());
我添加了 .error 功能,但它仍然没有工作:)