Skip to content

Commit 3d81bd9

Browse files
committed
chore: loading icon
1 parent 59c13af commit 3d81bd9

File tree

5 files changed

+62
-17
lines changed

5 files changed

+62
-17
lines changed

public/imgs/meidi.png

1.94 KB
Loading

src/app.css

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,35 @@ body {
3838
}
3939
}
4040

41+
42+
.loading-container {
43+
position: relative;
44+
width: 90%;
45+
max-width: 600px;
46+
height: 8px;
47+
border-radius: 6px;
48+
}
49+
50+
#loading-bar {
51+
width: 0%;
52+
height: 100%;
53+
background-color: #ffe65a;
54+
transition: width 0.2s ease;
55+
height: 100%;
56+
border-radius: 4px;
57+
position: relative;
58+
}
59+
60+
#loading-bar::after {
61+
content: "";
62+
position: absolute;
63+
top: -65px;
64+
right: -15px;
65+
width: 60px;
66+
height: 60px;
67+
background: url("/imgs/meidi.png") no-repeat center / contain;
68+
}
69+
4170
#loading-overlay {
4271
position: fixed;
4372
top: 0;
@@ -52,19 +81,16 @@ body {
5281
transition: opacity 0.1s ease-out;
5382
}
5483

55-
.loading-container {
56-
width: 80%;
57-
max-width: 400px;
58-
height: 8px;
59-
border-radius: 6px;
60-
overflow: hidden;
84+
85+
86+
@keyframes dog-jump {
87+
0% { transform: translateY(0); }
88+
30% { transform: translateY(-20px); }
89+
60% { transform: translateY(0); }
90+
80% { transform: translateY(-10px); }
91+
100% { transform: translateY(0); }
6192
}
6293

63-
#loading-bar {
64-
width: 100%;
65-
height: 100%;
66-
background-color: #ffe65a;
67-
transform: scaleX(0);
68-
transform-origin: left;
69-
transition: transform 0.2s ease;
94+
#loading-bar.done::after {
95+
animation: dog-jump 0.6s ease-out;
7096
}

src/config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
export function getBaseUrl() {
2+
try {
3+
const lang = navigator.language || '';
4+
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone || '';
5+
const inCN = /^zh-CN/i.test(lang) || tz.includes('Shanghai') || tz.includes('Beijing');
6+
7+
return inCN
8+
? 'https://gcore.jsdelivr.net/gh/douban-zoo/douban-zoo.github.io@gh-pages/'
9+
: import.meta.env.BASE_URL;
10+
} catch {
11+
return import.meta.env.BASE_URL;
12+
}
13+
}
14+
15+
export const asset = (path: string) => getBaseUrl() + path.replace(/^\/+/, '');
16+
117
export const config = {
218
numPages: 6,
319
pageWidth: 2.5,

src/lib/BookScene.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,20 @@ export class BookScene {
102102

103103
this.loadingManager.onProgress = (url, itemsLoaded, itemsTotal) => {
104104
const progressRatio = itemsLoaded / itemsTotal;
105-
(loadingBar as HTMLElement).style.transform = `scaleX(${ progressRatio })`;
105+
(loadingBar as HTMLElement).style.width = `${ progressRatio * 100 }%`;
106106
};
107107

108108
this.loadingManager.onLoad = () => {
109+
(loadingBar as HTMLElement).classList.add("done");
110+
109111
setTimeout(() => {
110112
this.renderable = true;
111113
}, 200);
112114

113115
gsap.to(loadingOverlay, {
114116
opacity: 0,
115-
duration: 1,
117+
duration: 0.3,
118+
delay: 0.3,
116119
onComplete: () => {
117120
loadingOverlay.style.visibility = 'hidden';
118121
}

src/lib/IconManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as THREE from 'three';
22
import gsap from 'gsap';
33
import { get } from 'svelte/store';
4-
import { config, assets, getPageId } from '../config';
4+
import { config, assets, asset, getPageId } from '../config';
55
import { playAudio } from '../utils/audios';
66
import { VideoOverlayManager } from './VideoOverlayManager';
77
import { currentPage } from '../store';
@@ -324,7 +324,7 @@ export class IconManager {
324324
const photoCount = assets.media[get(currentPage)]?.photo || 0;
325325
if (photoCount > 0) {
326326
const randomIndex = Math.floor(Math.random() * photoCount) + 1;
327-
const imagePath = `/imgs/${ this.pageId }/${ randomIndex }.png`;
327+
const imagePath = asset(`imgs/${ this.pageId }/${ randomIndex }.png`);
328328
this.showPhoto(imagePath);
329329
}
330330
}

0 commit comments

Comments
 (0)