-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid-cards.html
More file actions
83 lines (74 loc) · 2.33 KB
/
Copy pathgrid-cards.html
File metadata and controls
83 lines (74 loc) · 2.33 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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Demo</title>
<link rel="stylesheet" href="style.css">
<style>
.cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
gap: 2rem;
rule: 1px solid #c00;
rule-visibility-items: var(--visibility, normal);
}
.cards .card {
padding: 1rem;
background: #eee;
border-radius: 4px;
text-align: center;
}
</style>
</head>
<body class="needs-gap-decorations">
<div class="controls">
<p>
<label><input type="radio" name="visibility" value="normal" checked> normal(初期値。gridではallと同じ)</label>
<label><input type="radio" name="visibility" value="around"> around</label>
<label><input type="radio" name="visibility" value="between"> between</label>
</p>
<p>
アイテム数:
<button type="button" id="remove">-</button>
<output id="count">7</output>
<button type="button" id="add">+</button>
</p>
<p class="note">最終行に空きがある状態で見比べてください。</p>
</div>
<div class="cards" id="cards"></div>
<script>
const cards = document.getElementById("cards");
const count = document.getElementById("count");
let total = 7;
const render = () => {
cards.replaceChildren(
...Array.from({ length: total }, (_, i) => {
const div = document.createElement("div");
div.className = "card";
div.textContent = String(i + 1);
return div;
})
);
count.textContent = String(total);
};
document.getElementById("add").addEventListener("click", () => {
total = Math.min(total + 1, 16);
render();
});
document.getElementById("remove").addEventListener("click", () => {
total = Math.max(total - 1, 1);
render();
});
const applyVisibility = () => {
const checked = document.querySelector('input[name="visibility"]:checked');
cards.style.setProperty("--visibility", checked.value);
};
document.querySelectorAll('input[name="visibility"]').forEach((input) => {
input.addEventListener("change", applyVisibility);
});
applyVisibility();
render();
</script>
</body>
</html>