-
Notifications
You must be signed in to change notification settings - Fork 1
/
temp.js
60 lines (42 loc) · 1.16 KB
/
temp.js
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
const wrapper = document.getElementById("tiles");
let columns = 0,
rows = 0,
toggled = false;
const toggle = () => {
toggled = !toggled;
document.body.classList.toggle("toggled");
}
const handleOnClick = index => {
toggle();
anime({
targets: ".tile",
opacity: toggled ? 0 : 1,
delay: anime.stagger(50, {
grid: [columns, rows],
from: index
})
});
}
const createTile = index => {
const tile = document.createElement("div");
tile.classList.add("tile");
tile.style.opacity = toggled ? 0 : 1;
tile.onclick = e => handleOnClick(index);
return tile;
}
const createTiles = quantity => {
Array.from(Array(quantity)).map((tile, index) => {
wrapper.appendChild(createTile(index));
});
}
const createGrid = () => {
wrapper.innerHTML = "";
const size = document.body.clientWidth > 800 ? 100 : 50;
columns = Math.floor(document.body.clientWidth / size);
rows = Math.floor(document.body.clientHeight / size);
wrapper.style.setProperty("--columns", columns);
wrapper.style.setProperty("--rows", rows);
createTiles(columns * rows);
}
createGrid();
window.onresize = () => createGrid();