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