From 82efef8e4431415f2618ad5f2e3f967dbafbd079 Mon Sep 17 00:00:00 2001 From: surunzi Date: Sat, 19 Aug 2017 12:37:38 +0800 Subject: [PATCH] Dev: Auto scroll only at bottom --- src/Console/Logger.es6 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Console/Logger.es6 b/src/Console/Logger.es6 index 1e8221b..25a8a31 100644 --- a/src/Console/Logger.es6 +++ b/src/Console/Logger.es6 @@ -203,7 +203,10 @@ export default class Logger extends util.Emitter insert(type, args) { let logs = this._logs, - $el = this._$el; + $el = this._$el, + el = $el.get(0); + + let isAtBottom = (el.scrollTop === el.scrollHeight - el.offsetHeight); let options = util.isStr(type) ? {type, args} : type; util.extend(options, { @@ -237,7 +240,8 @@ export default class Logger extends util.Emitter if (this._filterLog(log) && this._parent.active) $el.append(log.formattedMsg); this.emit('insert', log); - this.scrollToBottom(); + + if (isAtBottom) this.scrollToBottom(); return this; } @@ -245,7 +249,7 @@ export default class Logger extends util.Emitter { let el = this._$el.get(0); - el.scrollTop = el.scrollHeight; + el.scrollTop = el.scrollHeight - el.offsetHeight; } _filterLogs(logs) {