-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (35 loc) · 1.33 KB
/
script.js
File metadata and controls
46 lines (35 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.getElementById("generateButton").addEventListener("click", () => {
const inputText = document.getElementById("textInput").value.toUpperCase();
const outputElement = document.getElementById("outputText");
// Helper function to adjust the font size dynamically
function adjustFontSize() {
const containerWidth = document.querySelector(".container").offsetWidth;
let fontSize = 100; // Starting font size
outputElement.style.fontSize = `${fontSize}px`;
while (outputElement.offsetWidth > containerWidth) {
fontSize--;
outputElement.style.fontSize = `${fontSize}px`;
}
}
let iteration = 0;
clearInterval(outputElement.interval);
outputElement.dataset.value = inputText;
outputElement.innerText = inputText;
adjustFontSize(); // Call the function to adjust the font size
outputElement.interval = setInterval(() => {
outputElement.innerText = outputElement.innerText
.split("")
.map((letter, index) => {
if (index < iteration) {
return outputElement.dataset.value[index];
}
return letters[Math.floor(Math.random() * 26)];
})
.join("");
if (iteration >= outputElement.dataset.value.length) {
clearInterval(outputElement.interval);
}
iteration += 1 / 3;
}, 30);
});