pinafore/routes/_components/VirtualList.html

51 lines
1.3 KiB
HTML
Raw Normal View History

2018-01-17 08:16:15 +01:00
<div class="virtual-list">
<!-- <div class="virtual-list-viewport" ref:viewport></div> -->
2018-01-16 02:25:32 +01:00
{{#each $visibleItems as item @key}}
<VirtualListItem :component
offset="{{item.offset}}"
props="{{item.props}}"
key="{{item.key}}"
/>
2018-01-15 19:54:02 +01:00
{{/each}}
</div>
<style>
.virtual-list {
position: relative;
}
</style>
<script>
import VirtualListItem from './VirtualListItem'
import { virtualListStore } from '../_utils/virtualListStore'
2018-01-15 19:54:02 +01:00
2018-01-17 06:43:31 +01:00
const DISTANCE_FROM_BOTTOM_TO_FIRE = 400
2018-01-16 02:25:32 +01:00
2018-01-15 19:54:02 +01:00
export default {
2018-01-16 02:25:32 +01:00
oncreate () {
this.observe('items', (items) => {
2018-01-16 01:12:07 +01:00
this.store.set({
2018-01-17 08:16:15 +01:00
items: items
2018-01-16 01:12:07 +01:00
})
2018-01-15 19:54:02 +01:00
})
2018-01-17 08:16:15 +01:00
this.observe('distanceFromBottom', (distanceFromBottom) => {
//console.log('distanceFromBottom', distanceFromBottom)
if (distanceFromBottom > 0 && // hack: the first it's reported, it's always 0
2018-01-17 06:43:31 +01:00
distanceFromBottom <= DISTANCE_FROM_BOTTOM_TO_FIRE) {
this.fire('scrollToBottom')
}
})
2018-01-16 03:29:28 +01:00
},
2018-01-15 19:54:02 +01:00
data: () => ({
component: null
2018-01-15 19:54:02 +01:00
}),
store: () => virtualListStore,
2018-01-15 19:54:02 +01:00
components: {
VirtualListItem
2018-01-17 08:16:15 +01:00
},
computed: {
distanceFromBottom: ($scrollHeight, $scrollTop, $offsetHeight) => {
return $scrollHeight - $scrollTop - $offsetHeight
}
2018-01-15 19:54:02 +01:00
}
}
</script>