57 lines
1.4 KiB
HTML
57 lines
1.4 KiB
HTML
<:Window bind:innerHeight='innerHeight'/>
|
|
<div class="virtual-list" style="height: {{$height}}px;">
|
|
<!-- <div class="virtual-list-viewport" ref:viewport></div> -->
|
|
{{#each $visibleItems as item @key}}
|
|
<VirtualListItem :component
|
|
offset="{{item.offset}}"
|
|
props="{{item.props}}"
|
|
key="{{item.key}}"
|
|
/>
|
|
{{/each}}
|
|
</div>
|
|
<style>
|
|
.virtual-list {
|
|
position: relative;
|
|
}
|
|
</style>
|
|
<script>
|
|
import VirtualListItem from './VirtualListItem'
|
|
import { virtualListStore } from '../_utils/virtualListStore'
|
|
import throttle from 'lodash/throttle'
|
|
|
|
const THROTTLE_TIME = 500
|
|
|
|
export default {
|
|
oncreate () {
|
|
this.observe('innerHeight', throttle(innerHeight => {
|
|
//console.log('setting innerHeight', innerHeight)
|
|
this.store.set({
|
|
innerHeight: innerHeight
|
|
})
|
|
}, THROTTLE_TIME))
|
|
this.observe('items', (items) => {
|
|
//console.log('setting items')
|
|
this.store.set({
|
|
'items': items
|
|
})
|
|
})
|
|
document.body.querySelector('.container').addEventListener('scroll', throttle((e) => {
|
|
this.store.set({
|
|
scrollTop: e.target.scrollTop
|
|
}, {
|
|
leading: false,
|
|
trailing: true
|
|
})
|
|
}, THROTTLE_TIME))
|
|
},
|
|
ondestroy () {
|
|
},
|
|
data: () => ({
|
|
component: null
|
|
}),
|
|
store: () => virtualListStore,
|
|
components: {
|
|
VirtualListItem
|
|
}
|
|
}
|
|
</script> |