-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
DancingLetters.html
126 lines (113 loc) · 3.21 KB
/
DancingLetters.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dancing Letters</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
text-align: center;
padding-top: 100px;
overflow: hidden;
}
.video-background {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
z-index: -1;
opacity: 0.5;
filter: brightness(50%) blur(5%);
}
input {
height: 2rem;
width: 20rem;
}
input::placeholder {
padding: 0 1rem;
}
h1 {
font-weight: bolder;
}
.letter {
position: absolute;
animation: bounce 1s infinite ease-in-out;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
@keyframes bounce {
0%,
100% {
transform: translateY(0);
}
50% {
transform: translateY(-20px);
}
}
</style>
</head>
<body>
<video autoplay muted loop class="video-background">
<source src="./assets/dance_video.mp4" type="video/mp4" />
</video>
<h1>Type anything Thing in your keyboard</h1>
<input
type="text"
placeholder="Type something..."
oninput="displayDancingLetters(event)"
/>
<script>
function displayDancingLetters(event) {
const text = event.target.value;
document
.querySelectorAll(".letter")
.forEach((letter) => letter.remove());
Array.from(text).forEach((char, index) => {
const letter = document.createElement("span");
letter.classList.add("letter");
letter.innerText = char;
letter.style.left = Math.random() * 90 + "vw";
letter.style.top = Math.random() * 80 + "vh";
letter.style.animationDelay = Math.random() * 0.5 + "s";
letter.style.color = getRandomDeepColor();
letter.style.fontSize = getRandomFontSize();
letter.style.fontWeight = getRandomFontWeight();
letter.style.fontFamily = getRandomFontStyle();
document.body.appendChild(letter);
});
}
function getRandomDeepColor() {
const r = Math.floor(Math.random() * 150) + 50;
const g = Math.floor(Math.random() * 150) + 50;
const b = Math.floor(Math.random() * 150) + 50;
return `rgb(${r},${g},${b})`;
}
function getRandomFontSize() {
const sizes = ["1.5rem", "2rem", "2.5rem", "3rem", "3.5rem"];
return sizes[Math.floor(Math.random() * sizes.length)];
}
function getRandomFontWeight() {
const weights = ["normal", "bold", "bolder"];
return weights[Math.floor(Math.random() * weights.length)];
}
function getRandomFontStyle() {
const fonts = [
"Arial",
"Georgia",
"Courier New",
"Times New Roman",
"Comic Sans MS",
"Cursive",
];
return fonts[Math.floor(Math.random() * fonts.length)];
}
</script>
</body>
</html>