Skip to content

Commit 9f95fef

Browse files
committed
add image loading with custom svg
1 parent acb2d29 commit 9f95fef

File tree

6 files changed

+89
-14
lines changed

6 files changed

+89
-14
lines changed

Diff for: src/components/InfiniteScrollView.vue

+12-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export default {
1313
pokeList: [],
1414
prev: "",
1515
next: "",
16-
isLoading: false
16+
isLoading: false,
17+
page: 1
1718
};
1819
},
1920
created() {
@@ -22,6 +23,11 @@ export default {
2223
mounted() {
2324
this.scroll();
2425
},
26+
watch: {
27+
page(num) {
28+
this.fetchData(this.next);
29+
}
30+
},
2531
methods: {
2632
fetchData(url = INITIAL_DOMAIN) {
2733
this.isLoading = true;
@@ -32,24 +38,24 @@ export default {
3238
this.prev = obj.prev;
3339
this.next = obj.next;
3440
this.pokeList = this.pokeList.concat(obj.list);
35-
}, 500);
41+
}, 600);
3642
})
3743
.finally(_ => {
3844
setTimeout(_ => {
3945
this.isLoading = false;
40-
}, 500);
46+
}, 600);
4147
});
4248
},
4349
scroll() {
44-
window.onscroll = () => {
50+
document.addEventListener("scroll", () => {
4551
let bottomOfWindow =
4652
document.documentElement.scrollTop + window.innerHeight ===
4753
document.documentElement.offsetHeight;
4854
4955
if (bottomOfWindow) {
50-
this.fetchData(this.next);
56+
this.page++;
5157
}
52-
};
58+
});
5359
}
5460
}
5561
};

Diff for: src/components/InfiniteScrollViewByLibrary.vue

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div
33
v-infinite-scroll="fetchData"
44
infinite-scroll-disabled="busy"
5-
infinite-scroll-distance="500"
5+
infinite-scroll-distance="1200"
66
>
77
<List :list="pokeList" />
88
</div>
@@ -28,7 +28,6 @@ export default {
2828
methods: {
2929
fetchData(url = INITIAL_DOMAIN) {
3030
this.isLoading = true;
31-
console.log(this.next);
3231
common
3332
.fetchList(this.next || url)
3433
.then(obj => {

Diff for: src/components/Loading.vue

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
<template>
2-
<div>Loding...</div>
2+
<div class="loading-image-wrapper"><LoadingSvg1 class="loading-image" /></div>
33
</template>
44

55
<script>
6-
export default {};
6+
import LoadingSvg1 from "./svg/SvgLoading.vue";
7+
8+
export default {
9+
components: { LoadingSvg1 }
10+
};
711
</script>
812

9-
<style></style>
13+
<style>
14+
.loading-image-wrapper {
15+
display: flex;
16+
justify-content: center;
17+
align-items: center;
18+
}
19+
</style>

Diff for: src/components/MoreButtonView.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ export default {
3232
this.prev = obj.prev;
3333
this.next = obj.next;
3434
this.pokeList = this.pokeList.concat(obj.list);
35-
}, 200);
35+
}, 600);
3636
})
3737
.finally(_ => {
3838
setTimeout(_ => {
3939
this.isLoading = false;
40-
}, 200);
40+
}, 600);
4141
});
4242
},
4343
onClickMoreBtn(e) {

Diff for: src/components/Pokemon.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ export default {
2929
.then(data => {
3030
this.pokemon = data;
3131
})
32-
.finally(_ => (this.isLoading = false));
32+
.finally(_ => {
33+
setTimeout(_ => {
34+
this.isLoading = false;
35+
}, 1200);
36+
});
3337
}
3438
};
3539
</script>

Diff for: src/components/svg/SvgLoading.vue

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<template>
2+
<svg
3+
version="1.1"
4+
xmlns="http://www.w3.org/2000/svg"
5+
xmlns:xlink="http://www.w3.org/1999/xlink"
6+
x="0px"
7+
y="0px"
8+
width="30px"
9+
height="8px"
10+
viewBox="0 0 30 8"
11+
enable-background="new 0 0 30 8"
12+
xml:space="preserve"
13+
>
14+
<rect x="0" y="0" width="8" height="8" fill="red" opacity=".2">
15+
<animate
16+
attributeName="opacity"
17+
attributeType="XML"
18+
values=".2 ; 1; .2"
19+
begin="0s"
20+
dur=".6s"
21+
repeatCount="indefinite"
22+
id="first"
23+
/>
24+
</rect>
25+
26+
<rect x="10" y="0" width="8" height="8" fill="red" opacity=".2">
27+
<animate
28+
attributeName="opacity"
29+
attributeType="XML"
30+
values=".2 ; 1; .2"
31+
begin="first.begin + .15s"
32+
dur=".6s"
33+
repeatCount="indefinite"
34+
id="second"
35+
/>
36+
</rect>
37+
38+
<rect x="20" y="0" width="8" height="8" fill="red" opacity=".2">
39+
<animate
40+
attributeName="opacity"
41+
attributeType="XML"
42+
values=".2 ; 1; .2"
43+
begin="second.begin + .15s"
44+
dur=".6s"
45+
repeatCount="indefinite"
46+
id="third"
47+
/>
48+
</rect>
49+
</svg>
50+
</template>
51+
52+
<script>
53+
export default {};
54+
</script>
55+
56+
<style></style>

0 commit comments

Comments
 (0)