Skip to content

Instantly share code, notes, and snippets.

@RshStone
Last active August 5, 2020 02:35
Show Gist options
  • Save RshStone/474b8ced5dea9a175b418f1c2ff2c5cb to your computer and use it in GitHub Desktop.
Save RshStone/474b8ced5dea9a175b418f1c2ff2c5cb to your computer and use it in GitHub Desktop.
Inputs and Events
<canvas id = "d1">
</canvas>
<p>
<input type = "color" value = ""#61d936" id = "clr" onchange = "doColor()" >
<input type = "range" min = "10" max = "100" value = "10" id = "cls" oninput = "doSquare()">
</p>
function changeColor(){
var dd1 = document.getElementById("d1");
dd1.style.backgroundColor = "green";
}
function doColor(){
var dd1 = document.getElementById("d1");
var colorinput = document.getElementById("clr");
var color = colorinput.value;
dd1.style.backgroundColor = color;
}
function doSquare(){
var dd1 = document.getElementById("d1");
var sizeinput = document.getElementById("cls");
var size = sizeinput.value;
var ctx = dd1.getContext("2d");
ctx.clearRect(0,0,dd1.width,dd1.height);
ctx.fillStyle = "yellow";
ctx.fillRect(10,10,size,size);
}
canvas{
width:200pt;
height:100pt;
margin:10px;
border: 1px solid lightgray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment