-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom Choice Picker.html
More file actions
212 lines (184 loc) · 6.29 KB
/
Random Choice Picker.html
File metadata and controls
212 lines (184 loc) · 6.29 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Choice Picker</title>
<style>
/* General Styles */
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background-color: #1a237e; /* Dark Blue Background */
color: #fff;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
}
.container {
width: 80%;
max-width: 600px;
padding: 2rem;
background-color: #283593; /* Slightly Lighter Dark Blue */
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}
h1 {
color: #ffca28; /* Golden Accent */
margin-bottom: 1.5rem;
font-size: 2.5rem;
}
/* Input Styles */
#choices {
width: 100%;
padding: 1rem;
margin-bottom: 1rem;
border: 2px solid #303f9f; /* Darker Blue Border */
border-radius: 4px;
background-color: #3f51b5; /* Even Lighter Dark Blue */
color: #fff;
font-size: 1rem;
box-sizing: border-box;
}
#choices:focus {
outline: none;
border-color: #ffca28; /* Golden Accent on Focus */
box-shadow: 0 0 5px rgba(255, 202, 40, 0.5);
}
/* Button Styles */
button {
background-color: #ffca28; /* Golden Accent */
color: #1a237e; /* Dark Blue Text */
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1.1rem;
transition: background-color 0.3s;
margin-right: 0.5rem;
}
button:hover {
background-color: #fbc02d; /* Slightly Darker Golden Accent */
}
button:disabled {
background-color: #7986cb; /* Light Blue for Disabled */
cursor: not-allowed;
}
/* Result Styles */
#result {
margin-top: 2rem;
font-size: 1.5rem;
color: #ffca28; /* Golden Accent */
font-weight: bold;
}
/* Tag Styles */
.tag {
background-color: #303f9f;
color: #fff;
border-radius: 5px;
padding: 0.5rem 1rem;
margin: 0.25rem;
font-size: 1rem;
display: inline-block;
}
.highlight {
background-color: #ffca28;
color: #1a237e;
}
#tags-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
margin-bottom: 1rem;
}
/* Responsive Design */
@media (max-width: 768px) {
.container {
width: 95%;
padding: 1.5rem;
}
h1 {
font-size: 2rem;
}
button {
font-size: 1rem;
padding: 0.6rem 1.2rem;
}
#result {
font-size: 1.2rem;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Random Choice Picker</h1>
<p>Enter all of the choices separated by a comma (','). Press enter when you're done.</p>
<textarea id="choices" placeholder="Enter choices here..."></textarea>
<div id="tags-container"></div>
<button onclick="pickChoice()" id="pick-button" disabled>Pick a Choice</button>
<button onclick="resetChoices()">Reset</button>
<div id="result"></div>
</div>
<script>
const choicesInput = document.getElementById('choices');
const tagsContainer = document.getElementById('tags-container');
const resultDiv = document.getElementById('result');
const pickButton = document.getElementById('pick-button');
choicesInput.addEventListener('input', (e) => {
const choices = e.target.value
.split(',')
.map(choice => choice.trim())
.filter(choice => choice !== '');
tagsContainer.innerHTML = ''; // Clear existing tags
choices.forEach(choice => {
const tag = document.createElement('span');
tag.classList.add('tag');
tag.innerText = choice;
tagsContainer.appendChild(tag);
});
pickButton.disabled = choices.length === 0; // Disable button if no choices
});
function pickChoice() {
const choicesText = choicesInput.value;
const choices = choicesText
.split(',')
.map(choice => choice.trim())
.filter(choice => choice !== '');
if (choices.length === 0) {
resultDiv.innerText = 'Please enter some choices.';
return;
}
// Highlight animation
const tags = document.querySelectorAll('.tag');
let index = 0;
const interval = setInterval(() => {
if (index > 0) {
tags[index - 1].classList.remove('highlight');
} else if (tags.length > 0) {
tags[tags.length - 1].classList.remove('highlight');
}
if (index < tags.length) {
tags[index].classList.add('highlight');
}
index++;
if (index > tags.length) {
clearInterval(interval);
tags[tags.length - 1].classList.remove('highlight'); // Ensure last tag is unhighlighted
const randomChoice = choices[Math.floor(Math.random() * choices.length)];
resultDiv.innerText = `The random choice is: ${randomChoice}`;
}
}, 100); // Adjust speed as needed
}
function resetChoices() {
choicesInput.value = '';
tagsContainer.innerHTML = '';
resultDiv.innerText = '';
pickButton.disabled = true;
}
</script>
</body>
</html>