UNPKG

3.45 kBMarkdownView Raw
1# vue-mugen-scroll [![NPM version](https://img.shields.io/npm/v/vue-mugen-scroll.svg?style=flat-square)](https://npmjs.com/package/vue-mugen-scroll) [![NPM downloads](https://img.shields.io/npm/dm/vue-mugen-scroll.svg?style=flat-square)](https://npmjs.com/package/vue-mugen-scroll) [![Build Status](https://img.shields.io/circleci/project/egoist/vue-mugen-scroll/master.svg?style=flat-square)](https://circleci.com/gh/egoist/vue-mugen-scroll)
2
3**むげん [mugen]** means Infinity in English.
4
5## Features
6
7- Small, only weighs 2kb
8- Insanely easy to use, it's just a component with a couple props
9
10## Install
11
12```bash
13$ npm install --save vue-mugen-scroll
14```
15
16CDN: https://unpkg.com/vue-mugen-scroll/dist/
17
18Demo: [JSFiddle](https://jsfiddle.net/jericopulvera/wq07brjs/17/)
19
20## Usage
21
22```vue
23<template>
24 <div id="app">
25 <div class="list">your list of items</div>
26 <!-- add the component right after your list -->
27 <mugen-scroll :handler="fetchData" :should-handle="!loading">
28 loading...
29 </mugen-scroll>
30 </div>
31</template>
32
33<script>
34 import MugenScroll from 'vue-mugen-scroll'
35 export default {
36 data() {
37 // do not run handler when it's loading
38 return {loading: false}
39 },
40 methods: {
41 fetchData() {
42 this.loading = true
43 // ... the code you wanna run to fetch data
44 this.loading = false
45 }
46 },
47 components: {MugenScroll}
48 }
49</script>
50```
51
52## API
53
54### props
55
56#### handler
57
58Type: `function`<br>
59Required: `true`
60
61The handler function to run after you scroll to the bottom of the list. It will also be invoked on component mounted and the `mugen-scroll` component is visible in viewport.
62
63#### handleOnMount
64
65Type: `boolean`<br>
66Default: `true`
67
68Invoke the handler function on component mounted.
69
70#### shouldHandle
71
72Type: `boolean`<br>
73Default: `true`
74
75Add an additional condition to check if it should invoke the handler function, for example you don't want it to be invoked again as it's loading.
76
77#### threshold
78
79Type: `number`<br>
80Default: `0`
81
82Set the ratio of the `<mugen-scroll>`'s height and width that needs to be visible for it to be considered in viewport. This defaults to 0, meaning any amount. A threshold of 0.5 or 1 will require that half or all, respectively, of the element's height and width need to be visible. threshold must be a number between 0 and 1
83
84#### scrollContainer
85
86Type: `string`
87
88If the container of your list is scrollable, you can specific the reference ID of the container, so that we can detect the `scroll` event of this element instead of `window`.
89
90```vue
91<template>
92 <div class="wrap"
93 <!-- the container is scrollable here -->
94 style="height: 200px; overflow: auto;"
95 <!-- add the ref -->
96 ref="wrap">
97 <div class="list"><!-- your list --></div>
98 <mugen-scroll
99 <!-- pass the ref id -->
100 scroll-container="wrap">
101 Loading...
102 </mugen-scroll>
103 </div>
104</template>
105```
106
107## Development
108
109You can run the example with [vbuild](https://github.com/egoist/vbuild)
110
111```bash
112git clone https://github.com/egoist/vue-mugen-scroll.git
113cd vue-mugen-scroll
114yarn
115yarn example
116```
117
118## Contributing
119
1201. Fork it!
1212. Create your feature branch: `git checkout -b my-new-feature`
1223. Commit your changes: `git commit -am 'Add some feature'`
1234. Push to the branch: `git push origin my-new-feature`
1245. Submit a pull request :D
125
126## License
127
128[MIT](https://egoist.mit-license.org/) © [EGOIST](https://github.com/egoist)