Only run popovers.hide_all() once on scroll start.

This function throttles the function and only allows the on scroll
event to fire the popovers.hide_all() function once on scroll start
(determined as > 250ms after the last scroll event fire on .app.

This should resolve some performance issues surrounding constantly
firing queries and potentially changing the document tree.
This commit is contained in:
Brock Whittaker 2017-01-26 10:57:27 -08:00 committed by Tim Abbott
parent b52f606c3a
commit 1a63f15382
1 changed files with 17 additions and 3 deletions

View File

@ -848,9 +848,23 @@ exports.register_click_handlers = function () {
}, true); }, true);
}); });
$('.app').on('scroll', function () { (function () {
popovers.hide_all(); var last_scroll = 0;
});
$('.app').on('scroll', function () {
var date = new Date().getTime();
// only run `popovers.hide_all()` if the last scroll was more
// than 250ms ago.
if (date - last_scroll > 250) {
popovers.hide_all();
}
// update the scroll time on every event to make sure it doesn't
// retrigger `hide_all` while still scrolling.
last_scroll = date;
});
}());
}; };