hi am having a problem with infinite scroll functionality, when all the contents have been displayed it still continues to scroll (strange behavior). i am looking for a way to stop the infinite scroll when all contents are displayed
here is my code
JavaScript
x
37
37
1
<script type="text/javascript">
2
jQuery(document).ready(function ($) {
3
(function () {
4
var page = 1,
5
loading = false,
6
finish = false;
7
8
9
function nearBottomOfPage() {
10
return $(window).scrollTop() > $(document).height() - $(window).height() - 200;
11
}
12
13
function finish() {
14
finish = true;
15
16
}
17
$(window).scroll(function () {
18
if (loading) {
19
return;
20
}
21
if (nearBottomOfPage() && !finish) {
22
loading = true;
23
$('#loader').show();
24
page++;
25
$.ajax({
26
url: '/office?page=' + page,
27
type: 'get',
28
dataType: 'script',
29
success: function () {
30
$('#loader').hide();
31
loading = false;
32
}
33
});
34
}
35
});
36
}());
37
i have bee working on this days now….please heeeeeeeeeeelllllllllpppppp 🙁
Advertisement
Answer
You can try unbinding it from window object. Suppose your last page reached then use this function
JavaScript
1
2
1
$(window).unbind('scroll');
2