Add background color for container and add more reset values
This commit is contained in:
parent
4fe377d9e1
commit
f7fa4dd325
2 changed files with 23 additions and 3 deletions
|
|
@ -22,11 +22,17 @@
|
||||||
<button class="pen" id="erase">Erase</button>
|
<button class="pen" id="erase">Erase</button>
|
||||||
<button id="reset">Reset</button>
|
<button id="reset">Reset</button>
|
||||||
|
|
||||||
<div id = col-picker>
|
<div id = "col-picker">
|
||||||
<label for="custom-color">Pick a color:</label>
|
<label for="custom-color">Pick a color:</label>
|
||||||
<input type="color" id="custom-color" value="#ff0000">
|
<input type="color" id="custom-color" value="#ff0000">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id = "background-col-picker">
|
||||||
|
<label for="back-col-picker">Pick a color:</label>
|
||||||
|
<input type="color" id="back-col-picker" value="#ff0000">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="slider">
|
<div class="slider">
|
||||||
<label for="gridSlider">Grid Size: <span id="sliderLabel"></span></label>
|
<label for="gridSlider">Grid Size: <span id="sliderLabel"></span></label>
|
||||||
<input name="gridSlider" id="gridSlider" type="range" min="1" max="100" value="16">
|
<input name="gridSlider" id="gridSlider" type="range" min="1" max="100" value="16">
|
||||||
|
|
|
||||||
16
script.js
16
script.js
|
|
@ -5,6 +5,7 @@ const gridSlider = document.querySelector("#gridSlider");
|
||||||
const buttons = document.querySelectorAll(".pen");
|
const buttons = document.querySelectorAll(".pen");
|
||||||
const colorPicker = document.querySelector("#custom-color");
|
const colorPicker = document.querySelector("#custom-color");
|
||||||
const reset = document.querySelector("#reset");
|
const reset = document.querySelector("#reset");
|
||||||
|
const backColorPicker = document.querySelector("#back-col-picker")
|
||||||
let colorValue = "black";
|
let colorValue = "black";
|
||||||
let numGrid = gridSlider.value;
|
let numGrid = gridSlider.value;
|
||||||
let sliderLabel = document.querySelector("#sliderLabel");
|
let sliderLabel = document.querySelector("#sliderLabel");
|
||||||
|
|
@ -23,7 +24,6 @@ let isErase;
|
||||||
|
|
||||||
createGrid();
|
createGrid();
|
||||||
|
|
||||||
|
|
||||||
buttons.forEach((button) => {
|
buttons.forEach((button) => {
|
||||||
button.addEventListener ("click", changeColor);
|
button.addEventListener ("click", changeColor);
|
||||||
});
|
});
|
||||||
|
|
@ -35,9 +35,18 @@ colorPicker.addEventListener("change", changeColor);
|
||||||
colorPicker.addEventListener("input", changeColor);
|
colorPicker.addEventListener("input", changeColor);
|
||||||
colorPicker.addEventListener("click", changeColor);
|
colorPicker.addEventListener("click", changeColor);
|
||||||
|
|
||||||
|
backColorPicker.addEventListener("change", pickBackground);
|
||||||
|
backColorPicker.addEventListener("input", pickBackground);
|
||||||
|
//backColorPicker.addEventListener("click", pickBackground);
|
||||||
|
|
||||||
reset.addEventListener("click", getGridDimensions);
|
reset.addEventListener("click", getGridDimensions);
|
||||||
|
|
||||||
|
|
||||||
|
function pickBackground() {
|
||||||
|
container.style.backgroundColor = backColorPicker.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function createGrid() {
|
function createGrid() {
|
||||||
const gridArea = numGrid ** 2;
|
const gridArea = numGrid ** 2;
|
||||||
const gridWidth = 100 / numGrid;
|
const gridWidth = 100 / numGrid;
|
||||||
|
|
@ -64,6 +73,11 @@ function createGrid() {
|
||||||
|
|
||||||
|
|
||||||
function getGridDimensions() {
|
function getGridDimensions() {
|
||||||
|
gridSlider.value = 16;
|
||||||
|
container.style.backgroundColor = "#ffffff";
|
||||||
|
backColorPicker.value = "#ffffff";
|
||||||
|
colorPicker.value = "#000000";
|
||||||
|
|
||||||
numGrid = gridSlider.value;
|
numGrid = gridSlider.value;
|
||||||
while (container.firstChild) {
|
while (container.firstChild) {
|
||||||
container.removeChild(container.lastChild);
|
container.removeChild(container.lastChild);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue