Add working opacity and transparency functions

This commit is contained in:
Octavia 2023-11-10 11:58:53 -07:00 • committed by GitHub
commit 441b621b6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,8 @@ let sliderLabel = document.querySelector("#sliderLabel");
let isRgb; let isRgb;
let isTint; let isTint;
let isShade; let isShade;
let isOpaque;
let isTrans;
buttons.forEach((button) => { buttons.forEach((button) => {
button.addEventListener ("click", changeColor); button.addEventListener ("click", changeColor);
@ -26,6 +28,7 @@ function createGrid() {
grid.classList.add("grid"); grid.classList.add("grid");
grid.style.width = gridWidth + '%'; grid.style.width = gridWidth + '%';
grid.style.height = gridWidth + '%'; grid.style.height = gridWidth + '%';
grid.style.opacity = 0.9;
for (let i = 0; i < gridArea; i++){ for (let i = 0; i < gridArea; i++){
container.appendChild(grid.cloneNode(true)); container.appendChild(grid.cloneNode(true));
@ -56,6 +59,10 @@ function colorGrid() {
this.style.background = tintColor(this.style.background); this.style.background = tintColor(this.style.background);
} else if (isShade) { } else if (isShade) {
this.style.background = shadeColor(this.style.background); this.style.background = shadeColor(this.style.background);
} else if (isOpaque){
this.style.opacity = makeOpaque(this.style.opacity);
} else if (isTrans) {
this.style.opacity = makeTransparent(this.style.opacity);
} else { } else {
this.style.background = colorValue; this.style.background = colorValue;
} }
@ -82,13 +89,22 @@ function changeColor() {
isShade = false isShade = false
} }
if (buttonID === "opacity") {
isOpaque = true;
} else {
isOpaque = false
}
if (buttonID === "trans") {
isTrans = true;
} else {
isTrans = false
}
switch (buttonID) { switch (buttonID) {
case "whiteColor": case "whiteColor":
colorValue = "rgb(255, 255, 255)"; colorValue = "rgb(255, 255, 255)";
break; break;
case "opacity":
colorValue = "blue";
break;
case "erase": case "erase":
colorValue = "transparent"; colorValue = "transparent";
break; break;
@ -124,5 +140,24 @@ function shadeColor(value) {
return`rgb(${r},${g},${b})`; return`rgb(${r},${g},${b})`;
} }
function makeOpaque(value) {
let num = +value;
if (num < 1){
num += .1
}
return num;
}
function makeTransparent(value) {
let num = +value;
if (num > 0){
num -= .1
}
return num;
}
createGrid(); createGrid();
//setGridListeners(); //setGridListeners();