Skip to content

Commit f89e714

Browse files
authored
Enhance loading image animation with smoothing
Refactor loading image animation logic to use linear interpolation for smoother transitions.
1 parent dedeae7 commit f89e714

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

web/installer.js

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,48 @@
1+
let currentPhase = 0; // current displayed phase
2+
let targetPhase = 0; // target phase you want to reach
3+
14
function loadingImg(phase) {
2-
const img = document.querySelector('.logo-img');
3-
if (!img) return;
5+
targetPhase = Math.max(0, Math.min(phase, 100));
6+
animatePhase();
7+
}
8+
9+
let animating = false;
10+
11+
function animatePhase() {
12+
if (animating) return; // prevent multiple loops
13+
animating = true;
14+
15+
function step() {
16+
const img = document.querySelector('.logo-img');
17+
if (!img) {
18+
animating = false;
19+
return;
20+
}
21+
22+
// smooth approach using linear interpolation
23+
currentPhase += (targetPhase - currentPhase) * 0.05; // 0.05 = smoothing factor
24+
if (Math.abs(currentPhase - targetPhase) < 0.1) currentPhase = targetPhase;
25+
26+
const degrees = (currentPhase / 100) * 360;
27+
28+
img.style.webkitMaskImage = `conic-gradient(rgba(255,255,255,1) 0deg ${degrees}deg, rgba(255,255,255,0.7) ${degrees}deg 360deg)`;
29+
img.style.maskImage = `conic-gradient(rgba(255,255,255,1) 0deg ${degrees}deg, rgba(255,255,255,0.7) ${degrees}deg 360deg)`;
30+
31+
img.style.webkitMaskRepeat = 'no-repeat';
32+
img.style.maskRepeat = 'no-repeat';
33+
img.style.webkitMaskPosition = 'center';
34+
img.style.maskPosition = 'center';
35+
img.style.webkitMaskSize = 'contain';
36+
img.style.maskSize = 'contain';
37+
38+
if (currentPhase !== targetPhase) {
39+
requestAnimationFrame(step);
40+
} else {
41+
animating = false;
42+
}
43+
}
444

5-
phase = Math.max(0, Math.min(phase, 100));
6-
const degrees = (phase / 100) * 360;
7-
8-
img.style.webkitMaskImage = `conic-gradient(rgba(255,255,255,1) 0deg ${degrees}deg, rgba(255,255,255,0.7) ${degrees}deg 360deg)`;
9-
img.style.maskImage = `conic-gradient(rgba(255,255,255,1) 0deg ${degrees}deg, rgba(255,255,255,0.7) ${degrees}deg 360deg)`;
10-
img.style.webkitMaskRepeat = 'no-repeat';
11-
img.style.maskRepeat = 'no-repeat';
12-
img.style.webkitMaskPosition = 'center';
13-
img.style.maskPosition = 'center';
14-
img.style.webkitMaskSize = 'contain';
15-
img.style.maskSize = 'contain';
45+
requestAnimationFrame(step);
1646
}
1747

1848
let pulseState = null;

0 commit comments

Comments
 (0)