Skip to content

Commit 8b116c6

Browse files
committed
Add custom root and wrap element tag support.
1 parent 2a793bd commit 8b116c6

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ The `<Item>` component is included inside but defined outside the `<virtualList>
6464

6565
```html
6666
<script src="https://unpkg.com/vue@2.0.0/dist/vue.js"></script>
67-
<script src="https://tangbc.github.io/vue-virtual-scroll-list/dist/vue-virtual-scroll-list.js"></script>
67+
<script src="https://tangbc.github.io/vue-virtual-scroll-list/index.js"></script>
6868

6969
<div id="app">
7070
<virtual-list :size="40" :remain="8">
@@ -80,7 +80,7 @@ new Vue({
8080
items: new Array(100000)
8181
},
8282
components: {
83-
'virtual-list': VirutalList
83+
'virtual-list': VirutalScrollList // Global name as `VirutalScrollList`
8484
}
8585
});
8686
```
@@ -94,6 +94,8 @@ new Vue({
9494
:--- | :--- | :--- | :--- |
9595
| size | Number || Each list item height, currently only supports fixed height. |
9696
| remain | Number || How many items except show in virtual-list viewport, so `size` and `remian` will determine the virtual-list outside container height (size × remian). |
97+
| rtag | String | * | Default value is `div`, the virtual-list's root HTMLElement tag name, in all case it's style is set to `display: block;` |
98+
| wtag | String | * | Default value is `div`, the virtual-list's item wrapper HTMLElement tag name, in all case it's style is set to `display: block;` |
9799
| onScroll | Function | * | Call on virtual-list scroll event hanlding, param: `(e, scrollTop)` |
98100
| toTop | Event | * | An event emit by virtual-list component when the list is scrolled on top. |
99101
| toBottom | Event | * | An event emit by virtual-list component when the list is scrolled on bottom. |

index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
} else {
99
root[moduleName] = factory(root['Vue'])
1010
}
11-
})(this, 'VirutalList', function (Vue2) {
11+
})(this, 'VirutalScrollList', function (Vue2) {
1212
'use strict'
1313

1414
return Vue2.component('vue-virtual-scroll-list', {
@@ -21,6 +21,14 @@
2121
type: Number,
2222
required: true
2323
},
24+
rtag: {
25+
type: String,
26+
default: 'div'
27+
},
28+
wtag: {
29+
type: String,
30+
default: 'div'
31+
},
2432
onScroll: Function
2533
},
2634

@@ -100,18 +108,20 @@
100108
var showList = this.filter(this.$slots.default)
101109
var delta = this.$options.delta
102110

103-
return createElement('div', {
111+
return createElement(this.rtag, {
104112
'ref': 'container',
105113
'style': {
114+
'display': 'block',
106115
'overflow-y': 'auto',
107116
'height': delta.viewHeight + 'px'
108117
},
109118
'on': {
110119
'scroll': this.handleScroll
111120
}
112121
}, [
113-
createElement('div', {
122+
createElement(this.wtag, {
114123
'style': {
124+
'display': 'block',
115125
'padding-top': delta.paddingTop + 'px',
116126
'padding-bottom': delta.allPadding - delta.paddingTop + 'px'
117127
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "vue-virtual-scroll-list",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "A vue (2.x) component support big data and infinite loading by using virtual scroll list.",
55
"main": "index.js",
66
"files": [
77
"index.js"
88
],
99
"scripts": {
10+
"dev": "webpack --watch --config ./dev/webpack.conf.js",
1011
"examples": "webpack --watch --config ./examples/webpack.conf.js"
1112
},
1213
"keywords": [

0 commit comments

Comments
 (0)