-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
108 lines (100 loc) · 3.12 KB
/
index.html
File metadata and controls
108 lines (100 loc) · 3.12 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Randomizer 🎲</title>
<style>
body {
font-family: Arial, sans-serif;
font-size: 20px;
text-align: center;
}
#input {
width: 100%;
max-width: 800px;
margin: 0 auto;
}
input {
width: 80%;
max-width: 640px;
}
input, button {
font-size: 1em;
}
#list {
list-style: none;
width: 100%;
max-width: 800px;
margin: 1em auto;
padding: 0;
}
.listItem {
display: flex;
justify-content: space-between;
padding: 0.5em 0.75em 0.5em 0.5em;
margin: 0.5em auto;
background: #f0f0f0;
border-radius: 10px;
transition: transform 0.5s ease-in-out, opacity 0.5s ease-in-out;
}
.listItem button {
font-size: 0.5em;
}
.highlight {
background: gold;
}
</style>
</head>
<body>
<h2>Randomizer 🎲</h2>
<div id="input">
<input type="text" id="textInput" placeholder="Enter text">
<button onclick="add()">➕</button>
<button onclick="randomize()">🎲</button>
</div>
<ul id="list"></ul>
<script>
const list = document.getElementById("list");
const textInput = document.getElementById("textInput");
textInput.addEventListener("keypress", function(event) {
if (event.key === "Enter") {
add();
}
});
function add() {
const text = textInput.value.trim();
if (!text) return;
const li = document.createElement("li");
li.className = "listItem";
li.innerHTML = `${text} <button onclick="remove(this.parentElement)">❌</button>`;
list.appendChild(li);
textInput.value = "";
}
function remove(li) {
li.style.transform = "translateY(-20px)";
li.style.opacity = "0";
setTimeout(() => li.remove(), 500);
}
function randomize() {
const items = document.querySelectorAll(".listItem");
if (items.length === 0) return;
let index = 0;
let iterations = items.length * 5 + Math.floor(Math.random() * items.length);
let speed = 50;
function cycle() {
items.forEach(item => item.classList.remove("highlight"));
items[index].classList.add("highlight");
if (iterations-- > 0) {
speed = Math.min(200, speed + 10);
setTimeout(cycle, speed);
index = (index + 1) % items.length;
} else {
setTimeout(() => remove(items[index]), 500);
}
}
cycle();
}
</script>
</body>
</html>