Skip to content

Commit 27a51bc

Browse files
committed
📦 1.2.0 💪 为元素增加了默认的index,使之渲染顺序更加稳定
1 parent c471475 commit 27a51bc

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133

134134
```html
135135
<scroll-viewport>
136-
<fixed-size-virtual-list
136+
<fixed-size-virtual-list-s1
137137
id="l"
138138
item-size="200"
139139
item-count="1000000"
@@ -157,7 +157,7 @@
157157
<div class="slider-item">rethink, this is grid.</div>
158158
</div>
159159
</virtual-list-custom-item>
160-
</fixed-size-virtual-list>
160+
</fixed-size-virtual-list-s1>
161161
</scroll-viewport>
162162
```
163163

demo.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
}
117117
</script>
118118
<scroll-viewport>
119-
<fixed-size-virtual-list
119+
<fixed-size-virtual-list-s1
120120
id="l"
121121
item-size="200"
122122
item-count="1000000"
@@ -140,5 +140,5 @@
140140
<div class="slider-item">rethink, this is grid.</div>
141141
</div>
142142
</virtual-list-custom-item>
143-
</fixed-size-virtual-list>
143+
</fixed-size-virtual-list-s1>
144144
</scroll-viewport>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bfchain/virtual-scroll",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"main": "dist/virtual-scroll.es.js",
55
"exports": {
66
".": "./dist/virtual-scroll.es.js"

src/common-fixed-size-virtual-list-builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ export abstract class CommonFixedSizeListBuilder<
488488
Number(index - viewStartIndex) * this.itemSize -
489489
koordinatenverschiebung;
490490
node.virtualVisible = true;
491+
node.virtualIndex = Number(index - viewStartIndex);
491492
}
492493

493494
/// 移除剩余的没有被重复利用的元素;(使用挪动到视图之外来替代移除,避免过度抖动)

src/virtual-list-common-item.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export abstract class VirtualListCommonItemElement extends LitElement {
88
top: 0;
99
transform: var(--virtual-transform);
1010
display: var(--virtual-display);
11+
z-index: var(--virtual-index);
1112
will-change: transform;
1213
--virtual-display: block;
1314
width: 100%;
@@ -30,6 +31,14 @@ export abstract class VirtualListCommonItemElement extends LitElement {
3031
this._virtualVisible = value;
3132
this._updateStyles();
3233
}
34+
private _virtualIndex = 0;
35+
public get virtualIndex(): number {
36+
return this._virtualIndex;
37+
}
38+
public set virtualIndex(value: number) {
39+
this._virtualIndex = value;
40+
this._updateStyles();
41+
}
3342
private _updating = false;
3443
protected _updateStyles() {
3544
if (this._updating) {
@@ -44,7 +53,7 @@ export abstract class VirtualListCommonItemElement extends LitElement {
4453
protected _getHostCssText() {
4554
let cssText: string;
4655
if (this._virtualVisible) {
47-
cssText = `--virtual-transform:translateY(${this._virtualTransformTop}px)`;
56+
cssText = `--virtual-transform:translateY(${this._virtualTransformTop}px);--virtual-index:${this._virtualIndex}`;
4857
} else {
4958
cssText = `--virtual-display:none`;
5059
}

0 commit comments

Comments
 (0)