pinafore/routes/_components/VirtualList.html

53 lines
1.4 KiB
HTML
Raw Normal View History

2018-01-16 00:12:07 +00:00
<:Window bind:scrollY='scrollY' bind:innerHeight='innerHeight' />
<div class="virtual-list" ref:node style="height: {{$height}}px;">
<!-- <div class="virtual-list-viewport" ref:viewport></div> -->
2018-01-16 00:12:07 +00:00
{{#each $visibleItems as item, virtualIndex}}
2018-01-15 18:54:02 +00:00
<VirtualListItem :component
2018-01-16 00:12:07 +00:00
offset="{{item.offset}}"
props="{{item.item.props}}"
index="{{item.item.index}}"
key="{{item.item.key}}"
/>
2018-01-15 18:54:02 +00:00
{{/each}}
</div>
<style>
.virtual-list {
position: relative;
}
</style>
<script>
import VirtualListItem from './VirtualListItem'
import { virtualListStore } from '../_utils/virtualListStore'
2018-01-15 18:54:02 +00:00
export default {
oncreate() {
2018-01-16 00:12:07 +00:00
console.log('scrollHeight', this.refs.node.scrollHeight)
this.store.set({
scrollHeight: this.refs.node.scrollHeight,
})
this.observe('innerHeight', innerHeight => {
this.store.set({
innerHeight: innerHeight
})
})
this.observe('items', (items) => {
2018-01-16 00:12:07 +00:00
this.store.set({
'items': items
})
2018-01-15 18:54:02 +00:00
})
this.observe('scrollY', (scrollY) => {
console.log('scrollY', scrollY)
2018-01-16 00:12:07 +00:00
this.store.set({
scrollTop: scrollY
})
2018-01-15 18:54:02 +00:00
})
},
data: () => ({
component: null
2018-01-15 18:54:02 +00:00
}),
store: () => virtualListStore,
2018-01-15 18:54:02 +00:00
components: {
VirtualListItem
}
}
</script>