-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathcat.vue
90 lines (83 loc) · 2.06 KB
/
cat.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<style scoped>
.cat-container {
position: fixed;
right: 50px;
bottom: 100px;
color: #00adb5;
}
.cat-container #vuepress-cat {
position: fixed;
opacity: 0.9;
right: 0px;
bottom: -20px;
z-index: 99999;
pointer-events: none;
}
</style>
<template>
<div class="cat-container" v-show="isLoaded">
<canvas
id="vuepress-cat"
:width="style.width"
:height="style.height"
class="live2d"
></canvas>
</div>
</template>
<script>
import live2dJSString from "./live2d";
export default {
name: "cat",
data() {
return {
isLoaded: true,
model: {
blackCat:
"https://cdn.jsdelivr.net/gh/QiShaoXuan/[email protected]/live2d-widget-model-hijiki/assets/hijiki.model.json",
whiteCat:
"https://cdn.jsdelivr.net/gh/QiShaoXuan/[email protected]/live2d-widget-model-tororo/assets/tororo.model.json"
},
style: {
width: 280,
height: 250
}
};
},
mounted() {
this.initCat();
this.$router.afterEach((to, from) => {
if (to.path !== from.path) {
this.initCat();
}
});
},
methods: {
initCat() {
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
)
? true
: false;
if (isMobile) {
this.isLoaded = false;
return console.log("mobile do not load model");
}
if (!window.loadlive2d) {
const script = document.createElement("script");
script.innerHTML = live2dJSString;
document.body.appendChild(script);
}
this.style = {
width: (150 / 1424) * document.body.clientWidth,
height: ((150 / 1424) * document.body.clientWidth) / 0.8
};
setTimeout(() => {
window.loadlive2d(
"vuepress-cat",
Math.random() > 0.5 ? this.model.blackCat : this.model.whiteCat
);
});
}
}
};
</script>