Skip to content

Commit

Permalink
πŸ› Fix scrollTo with layers (#17563)
Browse files Browse the repository at this point in the history
* Fix scrollTo with layers

* Add Math.max
  • Loading branch information
kevinkassimo authored and cathyxz committed Aug 24, 2018
1 parent 70eb785 commit a2f9c1d
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/service/viewport/viewport-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a2f9c1d

Please sign in to comment.