Rate limit scrolling callback

This commit is contained in:
Jessica B. Hamrick 2015-10-30 17:11:57 -07:00
parent 887e0dd154
commit 3bcd3417c2
2 changed files with 14 additions and 2 deletions

View File

@ -297,9 +297,9 @@ define(function (require) {
expand_time(time);
});
this.scroll_manager.element.scroll(function () {
this.scroll_manager.onScroll(function () {
that.update_marked_status();
});
}, 100);
// Firefox 22 broke $(window).on("beforeunload")
// I'm not sure why or how.
@ -738,6 +738,7 @@ define(function (require) {
};
Notebook.prototype.update_marked_status = function() {
console.log("update marked status");
var marked_cells = this.get_marked_cells();
var num_offscreen = 0;
var i;

View File

@ -13,6 +13,17 @@ define(['jquery'], function($){
this.animation_speed = options.animation_speed || 250; //ms
};
ScrollManager.prototype.onScroll = function (func, rate) {
/**
* Register a function to be called when the page is scrolled, throttled
* at a particular rate limit.
*/
this.element.scroll(function () {
clearTimeout(func._timeout);
func._timeout = setTimeout(func, rate);
});
};
ScrollManager.prototype.scroll = function (delta) {
/**
* Scroll the document.