aboutsummaryrefslogtreecommitdiff
path: root/p
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-10-16 15:10:21 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-10-16 15:10:21 +0200
commiteb88fee64bccfacbb8b1f5d84ba833d3a8286aa0 (patch)
tree2664a3b3d330b1655f42b5154098801babfd5628 /p
parentce14841cc05e500819c0cdb2c594be8b44e91e2d (diff)
Scroll performance
Fewer events, and ensure an event is fired after the end of the scroll. https://github.com/FreshRSS/FreshRSS/pull/1309
Diffstat (limited to 'p')
-rw-r--r--p/scripts/main.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js
index 400abf947..47d651d5b 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -449,21 +449,31 @@ function auto_share(key) {
}
}
+function scrollAsRead(box_to_follow) {
+ var minTop = 40 + (context.current_view === 'global' ? box_to_follow.offset().top : box_to_follow.scrollTop());
+ $('.not_read:visible').each(function () {
+ var $this = $(this);
+ if ($this.offset().top + $this.height() < minTop) {
+ mark_read($this, true);
+ }
+ });
+}
+
function init_posts() {
var box_to_follow = context.current_view === 'global' ? $("#panel") : $(window);
if (context.auto_mark_scroll) {
- var lastScroll = 0; //Throttle
+ var lastScroll = 0, //Throttle
+ timerId = 0;
box_to_follow.scroll(function () {
+ window.clearTimeout(timerId);
if (lastScroll + 500 < Date.now()) {
lastScroll = Date.now();
- $('.not_read:visible').each(function () {
- var $this = $(this),
- minTop = (context.current_view === 'global') ? box_to_follow.offset().top : box_to_follow.scrollTop();
- if ($this.offset().top + $this.height() < minTop + 40) {
- mark_read($this, true);
- }
- });
+ scrollAsRead(box_to_follow);
+ } else {
+ timerId = window.setTimeout(function() {
+ scrollAsRead(box_to_follow);
+ }, 500);
}
});
}