-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
73 lines (73 loc) · 2.61 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Abaco</title>
<style>
#container {
display: grid;
grid-template-columns: repeat(auto-fill, 80px);
grid-template-rows: repeat(10, 60px);
grid-auto-flow: column;
gap: 5px; /* Space between squares */
transform: scaleY(-1);
}
.square {
transform: scaleY(-1);
width: 50px;
height: 50px;
margin: 5px;
background-color: white;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
cursor: pointer;
border: 1px solid black;
}
.active {
background-color: red;
}
</style>
</head>
<body>
<div id="container">
<!-- Squares will be added here by JavaScript -->
</div>
<script src="https://code.jquery.com/jquery-3.7.1.slim.min.js" integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8=" crossorigin="anonymous"></script>
<script>
function makeSquares(max_number) {
const container = $("#container");
for (let i = 1; i <= max_number; i++) {
container.append($(`<div class="square" id="square-${i.toString().padStart(3,'0')}">${i}</div>`));
}
}
$(document).ready(function() {
const params = new URLSearchParams(window.location.search);
const param_max = parseInt(params.get("max"), 10) || 60;
console.log(param_max);
makeSquares(param_max);
$(".square").click(function() {
const are_all_inactive = $(".square").toArray().every(square => !square.classList.contains("active"));
if (are_all_inactive) {
if ($(this).text() == 1)
$(this).addClass("active");
} else {
if ($(this).hasClass("active")) {
const is_next_active = $(this).next().hasClass("active");
if (!is_next_active) {
$(this).removeClass("active");
}
} else {
const is_previous_active = $(this).prev().hasClass("active");
if (is_previous_active) {
$(this).addClass("active");
}
}
}
});
});
</script>
</body>
</html>