mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-04 18:53:26 +08:00
impr(loader): delay showing the loading bar by 125ms to avoid it flashing on screen for things that take a short time
!nuf
This commit is contained in:
parent
59636e9d05
commit
299fc35685
1 changed files with 19 additions and 1 deletions
|
@ -1,7 +1,25 @@
|
|||
let timeout: NodeJS.Timeout | null = null;
|
||||
|
||||
let visible = false;
|
||||
|
||||
function clearTimeout(): void {
|
||||
if (timeout !== null) {
|
||||
window.clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
}
|
||||
|
||||
export function show(): void {
|
||||
$("#backgroundLoader").stop(true, true).fadeIn(125);
|
||||
if (visible) return;
|
||||
timeout = setTimeout(() => {
|
||||
$("#backgroundLoader").stop(true, true).show();
|
||||
}, 125);
|
||||
visible = true;
|
||||
}
|
||||
|
||||
export function hide(): void {
|
||||
if (!visible) return;
|
||||
clearTimeout();
|
||||
$("#backgroundLoader").stop(true, true).fadeOut(125);
|
||||
visible = false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue