1- < div ref:viewport on:scroll ='refresh() ' style ='height: {height}; '>
1+ < div ref:viewport on:scroll ='refresh() ' style ='height: {height}; ' bind:offsetHeight =" viewportHeight " >
22 < div ref:container style ='padding-top: {_top}px; padding-bottom: {_bottom}px; '>
33 {#each visible as item (item.index)}
44 < div class ='row '>
5454 }
5555
5656 this . on ( 'state' , ( { changed, previous, current } ) => {
57- if ( changed . items || changed . height || changed . itemHeight ) {
57+ if ( changed . items || changed . height || changed . itemHeight || changed . viewportHeight ) {
5858 if ( current . itemHeight && ( changed . itemHeight || current . items . length > this . heightMap . length ) ) {
5959 this . heightMap = current . items . map ( ( ) => current . itemHeight ) ;
6060 }
8686
8787 methods : {
8888 initialise ( ) {
89- const { items, itemHeight } = this . get ( ) ;
90- const { viewport } = this . refs ;
91- const viewportHeight = viewport . offsetHeight ;
89+ const { items, itemHeight, viewportHeight } = this . get ( ) ;
9290
9391 if ( itemHeight ) {
9492 this . heightMap = items . map ( item => itemHeight ) ;
121119 } ,
122120
123121 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 ;
126124
127125 let paddingTop = 0 ;
128126 let offset = 0 ;
146144 const newStart = i ++ ;
147145
148146 for ( ; i < items . length ; i += 1 ) {
149- if ( offset >= scrollTop + offsetHeight ) break ;
147+ if ( offset >= scrollTop + viewportHeight ) break ;
150148 offset += this . heightMap [ i ] ;
151149 }
152150
179177 }
180178 }
181179 } ;
182- </ script >
180+ </ script >
0 commit comments