File tree 1 file changed +21
-1
lines changed
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 11
11
// read-only, but visible to consumers via bind:start
12
12
export let start = 0 ;
13
13
export let end = 0 ;
14
-
15
14
// local state
16
15
let height_map = [];
17
16
let rows;
33
32
$: if (mounted) refresh (items, viewport_height, itemHeight);
34
33
35
34
async function refresh (items , viewport_height , itemHeight ) {
35
+ const isStartOverflow = items .length < start
36
+
37
+ if (isStartOverflow) {
38
+ await scrollToIndex (items .length - 1 , {behavior: ' auto' })
39
+ }
40
+
36
41
const { scrollTop } = viewport;
37
42
38
43
await tick (); // wait until the DOM is up to date
105
110
bottom = remaining * average_height;
106
111
107
112
// prevent jumping if we scrolled up into unknown territory
113
+ return
108
114
if (start < old_start) {
109
115
await tick ();
110
116
127
133
// more. maybe we can just call handle_scroll again?
128
134
}
129
135
136
+ export async function scrollToIndex (index , opts ) {
137
+ const {scrollTop } = viewport;
138
+ const itemsDelta = index - start;
139
+ const _itemHeight = itemHeight || average_height;
140
+ const distance = itemsDelta * _itemHeight;
141
+ opts = {
142
+ left: 0 ,
143
+ top: scrollTop + distance,
144
+ behavior: ' smooth' ,
145
+ ... opts
146
+ };
147
+ viewport .scrollTo (opts);
148
+ }
149
+
130
150
// trigger initial refresh
131
151
onMount (() => {
132
152
rows = contents .getElementsByTagName (' svelte-virtual-list-row' );
You can’t perform that action at this time.
0 commit comments