-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (46 loc) · 1.37 KB
/
index.js
File metadata and controls
48 lines (46 loc) · 1.37 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
const gg = ({
selector = ".grid",
color = "rgb(240,128,128)",
opacity = 0.3,
showNumbers = true,
} = {}) => {
let clones = [];
const init = () => {
const grids = document.querySelectorAll(selector);
grids.forEach((grid) => {
grid.style.position = "relative";
const clone = grid.cloneNode();
clones.push(clone);
clone.style.cssText = `position: absolute; width: 100%; opacity: ${opacity}; height: 100%; min-height: 20px; pointer-events: none`;
grid.appendChild(clone);
let i = 1;
const addColumn = () => {
const col = document.createElement("div");
col.style.cssText = `background: ${color}; display: flex;`;
if (showNumbers) {
col.innerHTML += `<span>${i}</span>`;
const span = col.querySelector("span");
span.style.cssText =
"color: black; background: white; width: 20px; height: 20px; display: inline-flex; justify-content: center; font-size: 12px; align-items: center";
}
clone.appendChild(col);
if (col.offsetTop === 0) {
i++;
addColumn();
} else {
col.remove();
}
};
addColumn();
});
};
init();
const clear = () => {
clones.forEach((clone) => clone.remove());
};
window.addEventListener("resize", () => {
clear();
init();
});
};
module.exports = { gg };