Merge pull request #5208 from CodingFabian/debounce-scroll

Debounces scroll events in web viewer.
This commit is contained in:
Yury Delendik 2014-08-18 22:53:28 -05:00
commit 2f5c6d6c3a

View File

@ -274,20 +274,28 @@ var PDFView = {
watchScroll: function pdfViewWatchScroll(viewAreaElement, state, callback) {
state.down = true;
state.lastY = viewAreaElement.scrollTop;
viewAreaElement.addEventListener('scroll', function webViewerScroll(evt) {
if (!PDFView.pdfDocument) {
state.rAF = null;
viewAreaElement.addEventListener('scroll', function debounceScroll(evt) {
if (state.rAF) {
return;
}
var currentY = viewAreaElement.scrollTop;
var lastY = state.lastY;
if (currentY > lastY) {
state.down = true;
} else if (currentY < lastY) {
state.down = false;
}
// else do nothing and use previous value
state.lastY = currentY;
callback();
// schedule an invocation of webViewerScrolled for next animation frame.
state.rAF = window.requestAnimationFrame(function webViewerScrolled() {
state.rAF = null;
if (!PDFView.pdfDocument) {
return;
}
var currentY = viewAreaElement.scrollTop;
var lastY = state.lastY;
if (currentY > lastY) {
state.down = true;
} else if (currentY < lastY) {
state.down = false;
}
// else do nothing and use previous value
state.lastY = currentY;
callback();
});
}, true);
},