Merge pull request #5208 from CodingFabian/debounce-scroll
Debounces scroll events in web viewer.
This commit is contained in:
commit
2f5c6d6c3a
@ -274,20 +274,28 @@ var PDFView = {
|
|||||||
watchScroll: function pdfViewWatchScroll(viewAreaElement, state, callback) {
|
watchScroll: function pdfViewWatchScroll(viewAreaElement, state, callback) {
|
||||||
state.down = true;
|
state.down = true;
|
||||||
state.lastY = viewAreaElement.scrollTop;
|
state.lastY = viewAreaElement.scrollTop;
|
||||||
viewAreaElement.addEventListener('scroll', function webViewerScroll(evt) {
|
state.rAF = null;
|
||||||
if (!PDFView.pdfDocument) {
|
viewAreaElement.addEventListener('scroll', function debounceScroll(evt) {
|
||||||
|
if (state.rAF) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var currentY = viewAreaElement.scrollTop;
|
// schedule an invocation of webViewerScrolled for next animation frame.
|
||||||
var lastY = state.lastY;
|
state.rAF = window.requestAnimationFrame(function webViewerScrolled() {
|
||||||
if (currentY > lastY) {
|
state.rAF = null;
|
||||||
state.down = true;
|
if (!PDFView.pdfDocument) {
|
||||||
} else if (currentY < lastY) {
|
return;
|
||||||
state.down = false;
|
}
|
||||||
}
|
var currentY = viewAreaElement.scrollTop;
|
||||||
// else do nothing and use previous value
|
var lastY = state.lastY;
|
||||||
state.lastY = currentY;
|
if (currentY > lastY) {
|
||||||
callback();
|
state.down = true;
|
||||||
|
} else if (currentY < lastY) {
|
||||||
|
state.down = false;
|
||||||
|
}
|
||||||
|
// else do nothing and use previous value
|
||||||
|
state.lastY = currentY;
|
||||||
|
callback();
|
||||||
|
});
|
||||||
}, true);
|
}, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user