Skip to content

Commit 69bba9c

Browse files
committed
Update 3rd-party scroll plugin use for the v2.2.x
1 parent 835b29a commit 69bba9c

File tree

1 file changed

+82
-3
lines changed

1 file changed

+82
-3
lines changed

src/components/With3rdPartyScrollPlugin.vue

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22
<h3>Use with 3rd-party scroll plugin</h3>
33
<p>If you want to use this plugin with 3rd-party scroll plugin like <a target="_blank" href="https://github.com/noraesae/perfect-scrollbar">perfect-scrollbar</a>, you can set a special attribute called <code>infinite-wrapper</code> for your real scroll parent, this plugin will find the closest container which has <code>overflow-y: auto;</code> CSS style or has <code>infinite-wrapper</code> attribute as the scroll parent and listen it's scroll event.</p>
44
<p>The template should be like this:</p>
5-
<pre v-highlightjs>
5+
<pre v-if="$parent.docVersion < 2.2" v-highlightjs>
66
&lt;div id=&quot;perfect-scroll-wrapper&quot; ref=&quot;scrollWrapper&quot; infinite-wrapper&gt;
77
&lt;ul&gt;
88
&lt;li v-for=&quot;item in list&quot; v-text=&quot;item&quot;&gt;&lt;/li&gt;
99
&lt;/ul&gt;
1010
&lt;infinite-loading :on-infinite=&quot;onInfinite&quot; ref=&quot;infiniteLoading&quot;&gt;&lt;/infinite-loading&gt;
11+
&lt;/div&gt;</pre>
12+
<pre v-if="$parent.docVersion >= 2.2" v-highlightjs>
13+
&lt;div id=&quot;perfect-scroll-wrapper&quot; ref=&quot;scrollWrapper&quot; infinite-wrapper&gt;
14+
&lt;ul&gt;
15+
&lt;li v-for=&quot;item in list&quot; v-text=&quot;item&quot;&gt;&lt;/li&gt;
16+
&lt;/ul&gt;
17+
&lt;infinite-loading @infinite=&quot;infiniteHandler&quot;&gt;&lt;/infinite-loading&gt;
1118
&lt;/div&gt;</pre>
1219
<p>Script:</p>
13-
<pre v-highlightjs>
20+
<pre v-if="$parent.docVersion < 2.2" v-highlightjs>
1421
import Ps from 'perfect-scrollbar';
1522

1623
export default {
@@ -40,11 +47,42 @@ export default {
4047
components: {
4148
InfiniteLoading,
4249
},
50+
};</pre>
51+
<pre v-if="$parent.docVersion >= 2.2" v-highlightjs>
52+
import Ps from 'perfect-scrollbar';
53+
54+
export default {
55+
data() {
56+
return {
57+
list: [],
58+
};
59+
},
60+
mounted() {
61+
Ps.initialize(this.$refs.scrollWrapper);
62+
},
63+
methods: {
64+
infiniteHandler($state) {
65+
setTimeout(() =&gt; {
66+
const temp = [];
67+
for (let i = this.list.length + 1; i &lt;= this.list.length + 20; i++) {
68+
temp.push(i);
69+
}
70+
this.list = this.list.concat(temp);
71+
$state.loaded();
72+
this.$nextTick(() => {
73+
Ps.update(this.$refs.scrollWrapper);
74+
});
75+
}, 1000);
76+
},
77+
},
78+
components: {
79+
InfiniteLoading,
80+
},
4381
};</pre>
4482
<p>Now it will work properly with <code>perfect-scrollbar</code>!</p>
4583
<h4>With iScroll (or other plugin like it)</h4>
4684
<p>If you use this plugin with <a target="_blank" href="https://github.com/cubiq/iscroll"><code>iScroll</code></a>, it cannot work directly with <code>iScroll</code>, because the <code>iScroll</code> will not fire the scroll event after smooth scrolling, even if it can, this plugin also cannot get the correct <code>scrollTop</code> by strandard way, so we must use the following workaround:</p>
47-
<pre v-highlightjs>
85+
<pre v-if="$parent.docVersion < 2.2" v-highlightjs>
4886
import iScroll from 'iscroll/iscroll-probe';
4987

5088
export default {
@@ -85,5 +123,46 @@ export default {
85123
InfiniteLoading,
86124
},
87125
};</pre>
126+
<pre v-if="$parent.docVersion >= 2.2" v-highlightjs>
127+
import iScroll from 'iscroll/iscroll-probe';
128+
129+
export default {
130+
data() {
131+
return {
132+
list: [],
133+
iScroll,
134+
};
135+
},
136+
mounted() {
137+
this.iScroll = new IScroll(this.$refs.scrollWrapper, {
138+
probeType: 3, // see http://iscrolljs.com/#custom-events
139+
});
140+
this.iScroll.on('scroll', () => {
141+
let shouldBeCalled; // you should calculate the scroll top manually
142+
if (shouldBeCalled) {
143+
this.$refs.infiniteLoading.isLoading = true; // display the spinner manually
144+
this.$refs.infiniteLoading.$emit('infinite'); // emit the event manually
145+
}
146+
});
147+
},
148+
methods: {
149+
infiniteHandler($state) {
150+
setTimeout(() =&gt; {
151+
const temp = [];
152+
for (let i = this.list.length + 1; i &lt;= this.list.length + 20; i++) {
153+
temp.push(i);
154+
}
155+
this.list = this.list.concat(temp);
156+
$state.loaded();
157+
this.$nextTick(() => {
158+
this.iScroll.refresh();
159+
});
160+
}, 1000);
161+
},
162+
},
163+
components: {
164+
InfiniteLoading,
165+
},
166+
};</pre>
88167
<p>But is an ugly way, so if you have any good idea to solve it, please feedback to me in <a target="_blank" href="https://github.com/PeachScript/vue-infinite-loading/issues/44">this issue</a>, thank you very much!</p>
89168
</template>

0 commit comments

Comments
 (0)