-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (47 loc) · 2.39 KB
/
script.js
File metadata and controls
62 lines (47 loc) · 2.39 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Get the HTML element with the ID 'shuffling-heading' and store it in a variable
const heading = document.getElementById('shuffling-heading');
// Define the final text to display after shuffling
const finalText = "bruteforce";
// Set the duration (in milliseconds) for how long each letter shuffle lasts
const shuffleDuration = 100;
// Set the delay (in milliseconds) before revealing the next letter
const revealDelay = 500;
// Split the final text into an array of individual letters
const letters = finalText.split('');
// Create an array to hold the current state of letters, initialized with empty strings
const currentText = Array(finalText.length).fill('');
// Initialize a counter to track how many letters have been revealed
let revealedCount = 0;
// Function to shuffle the letters displayed in the heading
function shuffle() {
// Generate a shuffled string by mapping over the letters array
const shuffledText = letters.map((char, index) => {
// If the letter has been revealed, keep it; otherwise, generate a random letter
return currentText[index] || String.fromCharCode(Math.random() * 26 + 65).toLowerCase();
}).join(''); // Join the shuffled letters back into a single string
// Update the heading's inner text with the shuffled string
heading.innerText = shuffledText;
// Continue shuffling if not all letters have been revealed
if (revealedCount < finalText.length) {
// Call the shuffle function again after the specified duration
setTimeout(shuffle, shuffleDuration);
}
}
// Function to reveal letters of the final text one by one
function revealLetter() {
// Check if there are still letters to reveal
if (revealedCount < finalText.length) {
// Set the next letter in the currentText array to the corresponding letter in finalText
currentText[revealedCount] = finalText[revealedCount];
// Update the heading's inner text with the current text state
heading.innerText = currentText.join('');
// Increment the revealedCount to move to the next letter
revealedCount++;
// Call the revealLetter function again after the specified delay
setTimeout(revealLetter, revealDelay);
}
}
// Start the shuffling process
shuffle();
// Start revealing letters after a delay calculated based on the shuffle duration
setTimeout(revealLetter, shuffleDuration * (finalText.length + 1));