From a2f9c1d3fff343d4722b9e0d248dfa75a35c2448 Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Fri, 24 Aug 2018 12:24:59 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`scrollTo`=20with=20layers?= =?UTF-8?q?=20(#17563)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix scrollTo with layers * Add Math.max --- src/service/viewport/viewport-impl.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/service/viewport/viewport-impl.js b/src/service/viewport/viewport-impl.js index c5cf851d6d3a..a1f16e7594cd 100644 --- a/src/service/viewport/viewport-impl.js +++ b/src/service/viewport/viewport-impl.js @@ -555,19 +555,15 @@ export class Viewport { offset = 0; break; } - let newScrollTop; - let curScrollTopPromise; - if (this.useLayers_) { - newScrollTop = elementRect.top + offset; - curScrollTopPromise = Promise.resolve(0); - } else { - const calculatedScrollTop = elementRect.top - this.paddingTop_ + offset; - newScrollTop = Math.max(0, calculatedScrollTop); - curScrollTopPromise = this.getElementScrollTop_(parent); - } - - return curScrollTopPromise.then(curScrollTop => { + return this.getElementScrollTop_(parent).then(curScrollTop => { + let newScrollTop; + if (this.useLayers_) { + newScrollTop = Math.max(0, elementRect.top + offset + curScrollTop); + } else { + const calculatedScrollTop = elementRect.top - this.paddingTop_ + offset; + newScrollTop = Math.max(0, calculatedScrollTop); + } if (newScrollTop == curScrollTop) { return; }