Skip to content

Commit a4271c6

Browse files
[mirotalkc2c] - add shuffle text animation for random room and name generation
1 parent f4e9d1e commit a4271c6

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

frontend/css/home.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ body {
9898
box-shadow: 0 0 5px rgba(55, 109, 249, 0.3);
9999
}
100100

101+
.input-group input.shuffle-active,
102+
#userNameInput.shuffle-active {
103+
border-color: #376df9;
104+
box-shadow: 0 0 12px rgba(55, 109, 249, 0.5);
105+
transition: box-shadow 0.3s ease, border-color 0.3s ease;
106+
}
107+
101108
.input-btn {
102109
position: absolute;
103110
right: 8px;

frontend/js/home.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ async function initHome() {
4040
userNameIn.value = filterXSS(await getUserName());
4141

4242
randomRoomBtn.onclick = () => {
43-
roomIdIn.value = ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
44-
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
43+
const finalValue = ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
44+
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16),
4545
);
46+
shuffleText(roomIdIn, finalValue);
4647
};
4748

4849
randomUserBtn.onclick = () => {
49-
userNameIn.value = 'User_' + Math.floor(Math.random() * 1000000);
50+
const finalValue = 'User_' + Math.floor(Math.random() * 1000000);
51+
shuffleText(userNameIn, finalValue);
5052
};
5153

5254
joinBtn.onclick = () => {
@@ -66,6 +68,35 @@ async function initHome() {
6668
//...
6769
}
6870

71+
function shuffleText(input, finalValue, duration = 600) {
72+
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
73+
const steps = 10;
74+
const interval = duration / steps;
75+
let step = 0;
76+
77+
input.classList.add('shuffle-active');
78+
79+
const timer = setInterval(() => {
80+
step++;
81+
const progress = step / steps;
82+
let display = '';
83+
for (let i = 0; i < finalValue.length; i++) {
84+
if (i < finalValue.length * progress) {
85+
display += finalValue[i];
86+
} else {
87+
display += chars[Math.floor(Math.random() * chars.length)];
88+
}
89+
}
90+
input.value = display;
91+
92+
if (step >= steps) {
93+
clearInterval(timer);
94+
input.value = finalValue;
95+
setTimeout(() => input.classList.remove('shuffle-active'), 300);
96+
}
97+
}, interval);
98+
}
99+
69100
function elementDisplay(elem, display) {
70101
elem.style.display = display ? 'block' : 'none';
71102
}

0 commit comments

Comments
 (0)