mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 10:41:13 +08:00
fix(virtual-scroll): offset position
This commit is contained in:
@ -19,6 +19,7 @@ export class VirtualScroll {
|
|||||||
private cells: Cell[] = [];
|
private cells: Cell[] = [];
|
||||||
private virtualDom: VirtualNode[] = [];
|
private virtualDom: VirtualNode[] = [];
|
||||||
private isEnabled = false;
|
private isEnabled = false;
|
||||||
|
private viewportOffset = 0;
|
||||||
private currentScrollTop = 0;
|
private currentScrollTop = 0;
|
||||||
private indexDirty = 0;
|
private indexDirty = 0;
|
||||||
private totalHeight = 0;
|
private totalHeight = 0;
|
||||||
@ -153,6 +154,13 @@ export class VirtualScroll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.dom.read(() => {
|
this.dom.read(() => {
|
||||||
|
let topOffset = 0;
|
||||||
|
let node = this.el;
|
||||||
|
while (node !== this.scrollEl) {
|
||||||
|
topOffset += node.offsetTop;
|
||||||
|
node = node.parentElement;
|
||||||
|
}
|
||||||
|
this.viewportOffset = topOffset;
|
||||||
this.currentScrollTop = this.scrollEl.scrollTop;
|
this.currentScrollTop = this.scrollEl.scrollTop;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -160,7 +168,8 @@ export class VirtualScroll {
|
|||||||
const dirtyIndex = this.indexDirty;
|
const dirtyIndex = this.indexDirty;
|
||||||
|
|
||||||
// get visible viewport
|
// get visible viewport
|
||||||
const viewport = getViewport(this.currentScrollTop, this.viewportHeight, 100);
|
const scrollTop = this.currentScrollTop - this.viewportOffset;
|
||||||
|
const viewport = getViewport(scrollTop, this.viewportHeight, 100);
|
||||||
|
|
||||||
// compute lazily the height index
|
// compute lazily the height index
|
||||||
const heightIndex = this.getHeightIndex(viewport);
|
const heightIndex = this.getHeightIndex(viewport);
|
||||||
|
Reference in New Issue
Block a user