Skip to content

Commit 2197d49

Browse files
committed
fix(virtualScroll): first node should use clientTop/clientLeft
1 parent 6a52a4a commit 2197d49

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/components/virtual-scroll/test/image-gallery/main.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ion-header>
1+
<ion-header style="opacity: 0.9">
22
<ion-navbar>
33
<ion-title>Virtual Scroll: Image Gallery</ion-title>
44
<ion-buttons end>
@@ -10,7 +10,11 @@
1010
</ion-header>
1111

1212

13-
<ion-content>
13+
<ion-content fullscreen>
14+
15+
<h4 padding>
16+
Name these cars:
17+
</h4>
1418

1519
<ion-list [virtualScroll]="items"
1620
[headerFn]="headerFn"
@@ -37,6 +41,10 @@
3741

3842
</ion-list>
3943

44+
<h4 padding>
45+
How many did you get right?
46+
</h4>
47+
4048
</ion-content>
4149

4250
<style>

src/components/virtual-scroll/test/virtual-scroll.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ describe('VirtualScroll', () => {
543543
offsetHeight: height,
544544
offsetTop: top,
545545
offsetLeft: left,
546+
clientTop: top,
547+
clientLeft: left,
546548
style: {
547549
top: '',
548550
left: ''

src/components/virtual-scroll/virtual-util.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ export function initReadNodes(nodes: VirtualNode[], cells: VirtualCell[], data:
284284
if (nodes.length && cells.length) {
285285
// first node
286286
// ******** DOM READ ****************
287-
cells[0].top = getElement(nodes[0]).offsetTop;
287+
let firstEle = getElement(nodes[0]);
288+
cells[0].top = firstEle.clientTop;
289+
cells[0].left = firstEle.clientLeft;
288290
cells[0].row = 0;
289291

290292
// ******** DOM READ ****************
@@ -606,13 +608,14 @@ function calcHeight(viewportHeight: number, approxHeight: string): number {
606608
/**
607609
* NO DOM
608610
*/
609-
function getElement(node: VirtualNode) {
611+
function getElement(node: VirtualNode): HTMLElement {
610612
let rootNodes = node.view.rootNodes;
611613
for (var i = 0; i < rootNodes.length; i++) {
612614
if (rootNodes[i].nodeType === 1) {
613615
return rootNodes[i];
614616
}
615617
}
618+
return null;
616619
}
617620

618621

0 commit comments

Comments
 (0)