From b7e741ab801417b7475f90785fb23639cf35ba09 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Sun, 12 Aug 2018 01:42:49 +0200 Subject: [PATCH] fix(virtual-scroll): fix viewportOffset calculation fixes #14963 --- core/src/components/virtual-scroll/test/basic.html | 4 ++++ core/src/components/virtual-scroll/virtual-scroll.tsx | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/components/virtual-scroll/test/basic.html b/core/src/components/virtual-scroll/test/basic.html index 629b095685..a44dc98749 100644 --- a/core/src/components/virtual-scroll/test/basic.html +++ b/core/src/components/virtual-scroll/test/basic.html @@ -20,6 +20,10 @@ Add Items + + + + diff --git a/core/src/components/virtual-scroll/virtual-scroll.tsx b/core/src/components/virtual-scroll/virtual-scroll.tsx index 9d2cc17a8d..80620568c3 100644 --- a/core/src/components/virtual-scroll/virtual-scroll.tsx +++ b/core/src/components/virtual-scroll/virtual-scroll.tsx @@ -11,6 +11,7 @@ import { Range, calcCells, calcHeightIndex, doRender, findCellIndex, getRange, g }) export class VirtualScroll { + private contentEl?: HTMLElement; private scrollEl?: HTMLElement; private range: Range = { offset: 0, length: 0 }; private timerUpdate: any; @@ -121,6 +122,7 @@ export class VirtualScroll { } await contentEl.componentOnReady(); + this.contentEl = contentEl; this.scrollEl = contentEl.getScrollElement(); this.calcCells(); this.updateState(); @@ -215,14 +217,15 @@ export class VirtualScroll { } private readVS() { - const { scrollEl, el } = this; + const { contentEl, scrollEl, el } = this; let topOffset = 0; let node: HTMLElement | null = el; - while (node && node !== scrollEl) { + while (node && node !== contentEl) { topOffset += node.offsetTop; node = node.parentElement; } this.viewportOffset = topOffset; + console.log(this.viewportOffset); if (scrollEl) { this.viewportHeight = scrollEl.offsetHeight; this.currentScrollTop = scrollEl.scrollTop;