mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: only trigger infinitescroll on scroll end
This commit is contained in:
@@ -7,6 +7,7 @@ define('forum/infinitescroll', function () {
|
|||||||
var previousScrollTop = 0;
|
var previousScrollTop = 0;
|
||||||
var loadingMore = false;
|
var loadingMore = false;
|
||||||
var container;
|
var container;
|
||||||
|
var scrollTimeout = 0;
|
||||||
|
|
||||||
scroll.init = function (el, cb) {
|
scroll.init = function (el, cb) {
|
||||||
if (typeof el === 'function') {
|
if (typeof el === 'function') {
|
||||||
@@ -17,9 +18,19 @@ define('forum/infinitescroll', function () {
|
|||||||
container = el || $('body');
|
container = el || $('body');
|
||||||
}
|
}
|
||||||
previousScrollTop = $(window).scrollTop();
|
previousScrollTop = $(window).scrollTop();
|
||||||
$(window).off('scroll', onScroll).on('scroll', onScroll);
|
$(window).off('scroll', startScrollTimeout).on('scroll', startScrollTimeout);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function startScrollTimeout() {
|
||||||
|
if (scrollTimeout) {
|
||||||
|
clearTimeout(scrollTimeout);
|
||||||
|
}
|
||||||
|
scrollTimeout = setTimeout(function () {
|
||||||
|
scrollTimeout = 0;
|
||||||
|
onScroll();
|
||||||
|
}, 60);
|
||||||
|
}
|
||||||
|
|
||||||
function onScroll() {
|
function onScroll() {
|
||||||
var bsEnv = utils.findBootstrapEnvironment();
|
var bsEnv = utils.findBootstrapEnvironment();
|
||||||
var mobileComposerOpen = (bsEnv === 'xs' || bsEnv === 'sm') && $('html').hasClass('composing');
|
var mobileComposerOpen = (bsEnv === 'xs' || bsEnv === 'sm') && $('html').hasClass('composing');
|
||||||
@@ -34,7 +45,6 @@ define('forum/infinitescroll', function () {
|
|||||||
|
|
||||||
var top = 20;
|
var top = 20;
|
||||||
var bottom = 80;
|
var bottom = 80;
|
||||||
|
|
||||||
var direction = currentScrollTop > previousScrollTop ? 1 : -1;
|
var direction = currentScrollTop > previousScrollTop ? 1 : -1;
|
||||||
|
|
||||||
if (scrollPercent < top && currentScrollTop < previousScrollTop) {
|
if (scrollPercent < top && currentScrollTop < previousScrollTop) {
|
||||||
|
|||||||
@@ -223,13 +223,10 @@ define('forum/topic/posts', [
|
|||||||
}
|
}
|
||||||
|
|
||||||
Posts.loadMorePosts = function (direction) {
|
Posts.loadMorePosts = function (direction) {
|
||||||
if (!components.get('topic').length || navigator.scrollActive || Posts._infiniteScrollTimeout) {
|
if (!components.get('topic').length || navigator.scrollActive) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts._infiniteScrollTimeout = setTimeout(function () {
|
|
||||||
delete Posts._infiniteScrollTimeout;
|
|
||||||
}, 1000);
|
|
||||||
var replies = components.get('topic').find(components.get('post').not('[data-index=0]').not('.new'));
|
var replies = components.get('topic').find(components.get('post').not('[data-index=0]').not('.new'));
|
||||||
var afterEl = direction > 0 ? replies.last() : replies.first();
|
var afterEl = direction > 0 ? replies.last() : replies.first();
|
||||||
var after = parseInt(afterEl.attr('data-index'), 10) || 0;
|
var after = parseInt(afterEl.attr('data-index'), 10) || 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user