Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit d9a1aae

Browse files
committed
Improve loading bar transition effect
1 parent 2543a3b commit d9a1aae

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

framework/react/router.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,23 @@ export const Router: FC<RouterProps> = ({ ssrContext, suspense }) => {
184184
clearTimeout(loading);
185185
loadingBar.remove();
186186
} else {
187-
const fadeOutTime = 1.0;
188-
loadingBar.style.transition = `opacity ${fadeOutTime}s ease-in-out, width ${fadeOutTime}s ease-in-out`;
189-
setTimeout(() => {
187+
const moveOutTime = 0.7;
188+
const fadeOutTime = 0.3;
189+
const t1 = setTimeout(() => {
190190
loadingBar.style.opacity = "0";
191+
}, moveOutTime * 1000);
192+
const t2 = setTimeout(() => {
193+
global.__loading_bar_cleanup = null;
194+
loadingBar.remove();
195+
}, (moveOutTime + fadeOutTime) * 1000);
196+
global.__loading_bar_cleanup = () => {
197+
clearTimeout(t1);
198+
clearTimeout(t2);
199+
};
200+
loadingBar.style.transition = `opacity ${fadeOutTime}s ease-out, width ${moveOutTime}s ease-in-out`;
201+
setTimeout(() => {
191202
loadingBar.style.width = "100%";
192203
}, 0);
193-
global.__loading_bar_remove_timer = setTimeout(() => {
194-
global.__loading_bar_remove_timer = null;
195-
loadingBar.remove();
196-
}, fadeOutTime * 1000);
197204
}
198205
}, 0);
199206
if (e.url) {
@@ -310,9 +317,9 @@ function loadSSRModulesFromTag(): RouteModule[] {
310317
}
311318

312319
function getLoadingBar(): HTMLDivElement {
313-
if (typeof global.__loading_bar_remove_timer === "number") {
314-
clearTimeout(global.__loading_bar_remove_timer);
315-
global.__loading_bar_remove_timer = null;
320+
if (typeof global.__loading_bar_cleanup === "function") {
321+
global.__loading_bar_cleanup();
322+
global.__loading_bar_cleanup = null;
316323
}
317324
let bar = (document.getElementById("loading-bar") as HTMLDivElement | null);
318325
if (!bar) {
@@ -324,11 +331,12 @@ function getLoadingBar(): HTMLDivElement {
324331
position: "fixed",
325332
top: "0",
326333
left: "0",
334+
zIndex: "9999",
327335
width: "0",
328336
height: "1px",
329337
opacity: "0",
330338
background: "rgba(128, 128, 128, 0.9)",
331-
transition: "opacity 0.6s ease-in-out, width 3s ease-in-out",
339+
transition: "opacity 0.6s ease-in, width 3s ease-in",
332340
});
333341
return bar;
334342
}

0 commit comments

Comments
 (0)