-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdice..html
94 lines (92 loc) · 2.34 KB
/
dice..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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dice</title>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
flex-direction: row;
gap: 10px;
}
.dice {
height: 40px;
width: 40px;
padding: 7px 7px;
border-radius: 10px;
transition: 0.5s linear;
}
input[type="text"] {
outline: none;
padding: 4px 2px;
}
.items {
height: auto;
overflow-y: auto;
width: 50px;
padding: 5px 2px;
display: flex;
flex-direction: column;
gap: 5px;
border: 1px solid black;
max-height: 120px;
}
.btnItem {
height: 30px;
width: 40px;
border-radius: 10px;
}
::-webkit-scrollbar {
width: 5px !important;
background-color: white;
height: 5px !important;
}
::-webkit-scrollbar-track {
height: 10px;
}
</style>
</head>
<body>
<div style="display: flex; flex-direction: column; gap: 5px">
<input type="text" placeholder="place your bet" />
<button class="dice" id="dice">3</button>
</div>
<div class="items"></div>
<script type="text/javascript" charset="UTF-8">
const diceEl = document.getElementById("dice");
const itemsEl = document.querySelector(".items");
let items = [];
diceEl.addEventListener("click", () => {
let count = 0;
const timer = setInterval(() => {
diceEl.disabled = true;
count++;
let random = Math.ceil(Math.random() * 6);
diceEl.textContent = random;
if (count === 10) {
clearInterval(timer);
diceEl.disabled = false;
items.push(random);
setItems(items);
}
}, 100);
});
function setItems(items) {
let content = "";
for (let i = items.length - 1; i >= 0; i--) {
content += `<button class="btnItem">${items[i]}</button>`;
}
itemsEl.innerHTML = content;
}
</script>
</body>
</html>