Change grid size with slider

This commit is contained in:
lolabird 2023-11-09 20:15:53 -07:00
commit 012f0b29e5
3 changed files with 24 additions and 4 deletions

View file

@ -8,7 +8,13 @@
</head> </head>
<body> <body>
<h1>Etch-A-Sketch</h1> <h1>Etch-A-Sketch</h1>
<div class="area"> <div class="area">
<div class = "user-input">
<input id = "gridSlider" type="range" min="1" max="100" value="16">
</div>
<div class="container"> <div class="container">
</div> </div>

View file

@ -4,6 +4,8 @@ const container = document.querySelector(".container");
const conWidth = container.clientWidth; const conWidth = container.clientWidth;
const conHeight = container.clientHeight const conHeight = container.clientHeight
const grid = document.createElement("div"); const grid = document.createElement("div");
const gridSlider = document.querySelector("#gridSlider");
function createGrid() { function createGrid() {
const gridArea = numGrid ** 2; const gridArea = numGrid ** 2;
@ -24,13 +26,22 @@ function createGrid() {
item.addEventListener("mouseover", colorGrid); item.addEventListener("mouseover", colorGrid);
}); });
gridSlider.addEventListener("change", getGridDimensions);
}
function getGridDimensions() {
numGrid = gridSlider.value;
while (container.firstChild) {
container.removeChild(container.lastChild);
}
console.log(numGrid);
createGrid();
} }
function colorGrid() { function colorGrid() {
this.style.background = "blue"; this.style.background = "blue";
} }
createGrid();
createGrid();

View file

@ -4,6 +4,7 @@ body{
} }
.area{ .area{
display: flex; display: flex;
flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 90vh; height: 90vh;
@ -19,4 +20,6 @@ body{
.grid { .grid {
border: 1px solid #bbb; border: 1px solid #bbb;
box-sizing: border-box; box-sizing: border-box;
min-height: 0;
overflow: hidden;
} }