Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,26 @@ According to the demos above, here are lists of approximate statistics:

<img height="256" src="https://tangbc.github.io/github-images/vitual-scroll-list-prop-type.png">

| Prop | Type | Required | Description |
|-----------|---------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| size | Number | ✓ | Each list item height, in variable height, this prop just use to calculate the virtual-list outside container viewport fixed height. |
| remain | Number | ✓ | How many items should be shown in virtual-list viewport, so `size` and `remain` determine the outside container viewport height (`size × remian`). |
| bench | Number | * | Default value is equal to `remain`, unreached items count, not show in virtual-list viewport but exist in real DOM, the larger the bench, the higher the scroll performance will achieved. |
| start | Number | * | Default value is `0`, the initial scroll start index. It must be integer and in the range of list index, if invalid there will be effected as `0` or the last one. |
| offset | Number | * | Default value is `0`, the initial scroll offset. If both `start` and `offset` are assigned at initialization, `start` is preferred. |
| debounce | Number | * | It's disabled by default, milliseconds of using `debounce` function to ensure scroll event doesn't fire so often that it bricks browser performance. |
| rtag | String | * | Default value is `div`, the virtual-list root element tag name, in all cases it's style is set to `display: block;` |
| wtag | String | * | Default value is `div`, the virtual-list item wrapper element tag name, in all cases it's style is set to `display: block;` |
| wclass | String | * | Default is no classname, the virtual-list item wrapper element class, if assign this prop, you better **not** to change it's [CSS box model](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model). |
| pagemode | Boolean | * | Let virtual-list scroll with page viewport. |
| totop | Function | * | Called when virtual-list is scrolled to top, no param. |
| tobottom | Function | * | Called when virtual-list is scrolled to bottom, no param. |
| onscroll | Function | * | Called when virtual-list is scrolling, with param: [`(event, data)`](https://github.com/tangbc/vue-virtual-scroll-list/releases/tag/v1.1.7). |
| variable | Function or Boolean | * | Used in variable height, if assign `Function`, this prop is a variable height getter function which is called with param: `(index)` when each item is ready to be calculated; if assign `Boolean`, virtual-list will get each item variable height by it's inline style height automatic. |
| item | Component | * | Using in `item-mode`, list item vue component. |
| itemcount | Number | * | Using in `item-mode`, list data total counts. |
| itemprops | Function | * | Using in `item-mode`, a function call when each item is going to be rendered. |
| Prop | Type | Required | Description |
|---------------|---------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| size | Number | ✓ | Each list item height, in variable height, this prop just use to calculate the virtual-list outside container viewport fixed height. |
| remain | Number | ✓ | How many items should be shown in virtual-list viewport, so `size` and `remain` determine the outside container viewport height (`size × remian`). |
| bench | Number | * | Default value is equal to `remain`, unreached items count, not show in virtual-list viewport but exist in real DOM, the larger the bench, the higher the scroll performance will achieved. |
| start | Number | * | Default value is `0`, the initial scroll start index. It must be integer and in the range of list index, if invalid there will be effected as `0` or the last one. |
| offset | Number | * | Default value is `0`, the initial scroll offset. If both `start` and `offset` are assigned at initialization, `start` is preferred. |
| debounce | Number | * | It's disabled by default, milliseconds of using `debounce` function to ensure scroll event doesn't fire so often that it bricks browser performance. |
| rtag | String | * | Default value is `div`, the virtual-list root element tag name, in all cases it's style is set to `display: block;` |
| wtag | String | * | Default value is `div`, the virtual-list item wrapper element tag name, in all cases it's style is set to `display: block;` |
| wclass | String | * | Default is no classname, the virtual-list item wrapper element class, if assign this prop, you better **not** to change it's [CSS box model](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model). |
| pagemode | Boolean | * | Let virtual-list scroll with page viewport. |
| scrollelement | HTMLElement | * | Let virtual-list scroll with a parent element. Note: to scroll with page viewport, use pagemode instead. When pagemode is true, scrollelement is ignored. |
| totop | Function | * | Called when virtual-list is scrolled to top, no param. |
| tobottom | Function | * | Called when virtual-list is scrolled to bottom, no param. |
| onscroll | Function | * | Called when virtual-list is scrolling, with param: [`(event, data)`](https://github.com/tangbc/vue-virtual-scroll-list/releases/tag/v1.1.7). |
| variable | Function or Boolean | * | Used in variable height, if assign `Function`, this prop is a variable height getter function which is called with param: `(index)` when each item is ready to be calculated; if assign `Boolean`, virtual-list will get each item variable height by it's inline style height automatic. |
| item | Component | * | Using in `item-mode`, list item vue component. |
| itemcount | Number | * | Using in `item-mode`, list data total counts. |
| itemprops | Function | * | Using in `item-mode`, a function call when each item is going to be rendered. |


## Public methods
Expand Down
2 changes: 1 addition & 1 deletion demos/item-mode/build.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demos/page-mode/build.js

Large diffs are not rendered by default.

100 changes: 100 additions & 0 deletions demos/scroll-element/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<template>
<div class="app">
<GithubCorner path="/scroll-element" />
<div ref="main" class="container">
<Header title="scroll-element"
:desciption="'Build ' + itemCount.toLocaleString() + ' items.'"
:start-index="start"
:on-data-change="onHeaderDataChange"
/>
<div class="main">
<virtual-list class="list"
:size="size"
:remain="remain"
:bench="30"
:start="start"
:scrollelement="scrollelement"

:item="item"
:itemcount="itemCount"
:itemprops="getItemProps"
/>
</div>
</div>
</div>
</template>

<script>
import Item from '../common/Item.vue'
import VirtualList from 'vue-virtual-scroll-list'
import { countStorage, getRandomUser } from '../common/util'

const remain = 14
const itemSize = 80
const itemCount = countStorage.get()

let userInfoList = []
for (let i = 0; i < itemCount; i++) {
userInfoList.push(getRandomUser())
}

export default {
name: 'App',

components: {
'virtual-list': VirtualList
},

data () {
return {
remain,
start: 0,
size: itemSize,
item: Item,
itemCount: itemCount,
scrollelement: null
}
},

mounted () {
this.scrollelement = this.$refs.main
},

methods: {
getItemProps (itemIndex) {
return {
key: itemIndex,
props: {
height: itemSize,
index: itemIndex,
info: userInfoList[itemIndex] || {}
}
}
},

onHeaderDataChange (type, value) {
if (type === 'start') {
this.start = value
}
}
}
}
</script>

<style lang="less">
@import '../common/app.less';

.app {
height: 100%;
}

.container {
display: flex;
flex-direction: column;

height: 100%;

overflow: auto;
}

</style>
13 changes: 13 additions & 0 deletions demos/scroll-element/build.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions demos/scroll-element/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>scroll-element demo of vue-virtual-scroll-list</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=0"/>
</head>
<body>
<div id="app"></div>
<script type="text/javascript" src="build.js"></script></body>
</html>
4 changes: 4 additions & 0 deletions demos/scroll-element/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import App from './App.vue'
import createApp from '../common/createApp'

createApp(App)
2 changes: 1 addition & 1 deletion demos/variable-height/build.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions demos/vfor-mode/build.js

Large diffs are not rendered by default.

Loading