1
- < div ref:viewport on:scroll ='refresh() ' style ='height: {height}; '>
1
+ < div ref:viewport on:scroll ='refresh() ' style ='height: {height}; ' bind:offsetHeight =" viewportHeight " >
2
2
< div ref:container style ='padding-top: {_top}px; padding-bottom: {_bottom}px; '>
3
3
{#each visible as item (item.index)}
4
4
< div class ='row '>
54
54
}
55
55
56
56
this . on ( 'state' , ( { changed, previous, current } ) => {
57
- if ( changed . items || changed . height || changed . itemHeight ) {
57
+ if ( changed . items || changed . height || changed . itemHeight || changed . viewportHeight ) {
58
58
if ( current . itemHeight && ( changed . itemHeight || current . items . length > this . heightMap . length ) ) {
59
59
this . heightMap = current . items . map ( ( ) => current . itemHeight ) ;
60
60
}
86
86
87
87
methods : {
88
88
initialise ( ) {
89
- const { items, itemHeight } = this . get ( ) ;
90
- const { viewport } = this . refs ;
91
- const viewportHeight = viewport . offsetHeight ;
89
+ const { items, itemHeight, viewportHeight } = this . get ( ) ;
92
90
93
91
if ( itemHeight ) {
94
92
this . heightMap = items . map ( item => itemHeight ) ;
121
119
} ,
122
120
123
121
refresh ( ) {
124
- const { items, start, end, itemHeight } = this . get ( ) ;
125
- const { offsetHeight , scrollTop } = this . refs . viewport ;
122
+ const { items, start, end, itemHeight, viewportHeight } = this . get ( ) ;
123
+ const { scrollTop } = this . refs . viewport ;
126
124
127
125
let paddingTop = 0 ;
128
126
let offset = 0 ;
146
144
const newStart = i ++ ;
147
145
148
146
for ( ; i < items . length ; i += 1 ) {
149
- if ( offset >= scrollTop + offsetHeight ) break ;
147
+ if ( offset >= scrollTop + viewportHeight ) break ;
150
148
offset += this . heightMap [ i ] ;
151
149
}
152
150
179
177
}
180
178
}
181
179
} ;
182
- </ script >
180
+ </ script >
0 commit comments