-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrid-effect.js
39 lines (26 loc) · 944 Bytes
/
grid-effect.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
const wrapper = document.querySelector(".why .effect-container");
const wrapper_grid = document.querySelector('.why .effect-container .grid-effect')
let columns = 0,
rows = 0;
const createTile = index => {
const tile = document.createElement("div");
tile.classList.add("tile");
tile.style.opacity = 0.3;
return tile;
}
const createTiles = quantity => {
Array.from(Array(quantity)).map((tile, index) => {
wrapper_grid.appendChild(createTile(index));
});
}
const createGrid = () => {
wrapper_grid.innerHTML = "";
const size = wrapper.clientWidth > 800 ? 100 : 100;
columns = Math.floor(wrapper.clientWidth / size);
rows = Math.floor(wrapper.clientHeight / size);
wrapper_grid.style.setProperty("--columns", columns);
wrapper_grid.style.setProperty("--rows", rows);
createTiles(columns * rows);
}
createGrid();
window.onresize = () => createGrid();