button style + add responsiveness to click

This commit is contained in:
awesomeuser 2023-08-04 19:08:38 +00:00
parent b811c80009
commit 4100c21702

View file

@ -5,6 +5,14 @@
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<style>
button {
background: var(--accent);
color: white;
font-weight: 600;
border: none;
cursor: pointer;
}
#center {
width: 100%;
max-width: 900px;
@ -125,8 +133,8 @@
<canvas id="canvas-input" width="128" height="64"></canvas>
<div style="border: 1px solid grey;">
<button type="button" onclick="setPen();">Pen</button>
<button type="button" onclick="setEraser();">Eraser</button>
<button type="button" onclick="setPen();" id="pen-button">Pen</button>
<button type="button" onclick="setEraser();" id="eraser-button">Eraser</button>
<button type="button" onclick="clearCanvas();" style="float: right;">Clear</button>
</div>
@ -149,11 +157,13 @@
for (let i = 0; i < pen.data.length; i += 4) {
pen.data[i+3] = 255;
}
const penButton = document.getElementById("pen-button");
const eraser = ctx.createImageData(2, 2);
for (let i = 0; i < eraser.data.length; i += 4) {
eraser.data[i+3] = 0;
}
const eraserButton = document.getElementById("eraser-button");
var currentTool = pen;
@ -190,10 +200,16 @@
function setPen() {
currentTool = pen;
penButton.style.textDecoration = "underline";
eraserButton.style.textDecoration = "none";
}
function setEraser() {
currentTool = eraser;
penButton.style.textDecoration = "none";
eraserButton.style.textDecoration = "underline";
}
function clearCanvas() {