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 |
|
16 | CDN: https://unpkg.com/vue-mugen-scroll/dist/
|
17 |
|
18 | Demo: [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 |
|
58 | Type: `function`<br>
|
59 | Required: `true`
|
60 |
|
61 | The 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 |
|
65 | Type: `boolean`<br>
|
66 | Default: `true`
|
67 |
|
68 | Invoke the handler function on component mounted.
|
69 |
|
70 | #### shouldHandle
|
71 |
|
72 | Type: `boolean`<br>
|
73 | Default: `true`
|
74 |
|
75 | Add 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 |
|
79 | Type: `number`<br>
|
80 | Default: `0`
|
81 |
|
82 | Set 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 |
|
86 | Type: `string`
|
87 |
|
88 | If 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 |
|
109 | You can run the example with [vbuild](https://github.com/egoist/vbuild)
|
110 |
|
111 | ```bash
|
112 | git clone https://github.com/egoist/vue-mugen-scroll.git
|
113 | cd vue-mugen-scroll
|
114 | yarn
|
115 | yarn example
|
116 | ```
|
117 |
|
118 | ## Contributing
|
119 |
|
120 | 1. Fork it!
|
121 | 2. Create your feature branch: `git checkout -b my-new-feature`
|
122 | 3. Commit your changes: `git commit -am 'Add some feature'`
|
123 | 4. Push to the branch: `git push origin my-new-feature`
|
124 | 5. Submit a pull request :D
|
125 |
|
126 | ## License
|
127 |
|
128 | [MIT](https://egoist.mit-license.org/) © [EGOIST](https://github.com/egoist)
|