Move grid creation to function
This commit is contained in:
parent
a48661fcf4
commit
06aa9203af
1 changed files with 20 additions and 13 deletions
33
script.js
33
script.js
|
|
@ -1,16 +1,23 @@
|
|||
const container = document.querySelector(".container");
|
||||
const conWidth = container.clientWidth;
|
||||
const conHeight = container.clientHeight
|
||||
const grid = document.createElement("div");
|
||||
let numGrid = 16;
|
||||
const gridArea = numGrid ** 2;
|
||||
const gridWidth = conWidth / numGrid;
|
||||
const gridHeight = conHeight / numGrid;
|
||||
function createGrid(num) {
|
||||
const container = document.querySelector(".container");
|
||||
const conWidth = container.clientWidth;
|
||||
const conHeight = container.clientHeight
|
||||
const grid = document.createElement("div");
|
||||
const gridArea = num ** 2;
|
||||
const gridWidth = conWidth / num;
|
||||
const gridHeight = conHeight / num;
|
||||
|
||||
grid.classList.add("grid");
|
||||
grid.style.width = gridWidth + 'px';
|
||||
grid.style.height = gridHeight + 'px';
|
||||
grid.classList.add("grid");
|
||||
grid.style.width = gridWidth + 'px';
|
||||
grid.style.height = gridHeight + 'px';
|
||||
|
||||
for (let i = 0; i < gridArea; i++){
|
||||
container.appendChild(grid.cloneNode(true));
|
||||
for (let i = 0; i < gridArea; i++){
|
||||
container.appendChild(grid.cloneNode(true));
|
||||
}
|
||||
}
|
||||
|
||||
let numGrid = 16; //will use this later to prompt user
|
||||
|
||||
createGrid(numGrid);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue