Guard the request animation frame with the existing requestFrame flag

This commit is contained in:
Michael Lange
2020-06-17 14:50:55 -07:00
parent 5bb3c434d8
commit 619aea8dbb

View File

@@ -52,11 +52,16 @@ export default class StreamingFile extends Component.extend(WindowResizable) {
scrollHandler() {
const cli = this.element;
window.requestAnimationFrame(() => {
// If the scroll position is close enough to the bottom, autoscroll to the bottom
this.set('follow', cli.scrollHeight - cli.scrollTop - cli.clientHeight < 20);
this.requestFrame = true;
});
// Scroll events can fire multiple times per frame, this eliminates
// redundant computation.
if (this.requestFrame) {
window.requestAnimationFrame(() => {
// If the scroll position is close enough to the bottom, autoscroll to the bottom
this.set('follow', cli.scrollHeight - cli.scrollTop - cli.clientHeight < 20);
this.requestFrame = true;
});
}
this.requestFrame = false;
}