-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
81 lines (45 loc) · 1.03 KB
/
main.js
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
(function(){
let loadExternal = [];
// 配置资源
const config = [
'./css/waifu.css',
'./css/font-awesome.css',
'./2D/LoadLive2D.js',
'./2D/Live2D.js',
'./data/text.js',
'./data/model.js',
'./js/init2D.js',
'./js/template.js'
];
config.forEach((paths)=>{
format = paths.split('.')[2];
loadExternal.push(loadExternalResource(paths,format))
})
// 加载资源
if (screen.width >= 768) {
Promise.all(loadExternal).then(() => {
initWidget();
// loadModes(6)
});
}
// 封装异步加载资源的方法
function loadExternalResource(url, type) {
return new Promise((resolve, reject) => {
let tag;
if (type === "css") {
tag = document.createElement("link");
tag.rel = "stylesheet";
tag.href = url;
}
else if (type === "js") {
tag = document.createElement("script");
tag.src = url;
}
if (tag) {
tag.onload = () => resolve(url);
tag.onerror = () => reject(url);
document.head.appendChild(tag);
}
});
}
})()