Skip to content

Instantly share code, notes, and snippets.

@tedrand
Created July 23, 2017 14:32
Show Gist options
  • Save tedrand/efe968c5593c6a9201808059ba8983b0 to your computer and use it in GitHub Desktop.
Save tedrand/efe968c5593c6a9201808059ba8983b0 to your computer and use it in GitHub Desktop.
Inputs
<h1>Working with Input Types</h1>
<canvas id="can"></canvas>
<input id="clr" type="color"
onchange="setColor()">
<input id="rng" type="range"
onchange="doSquare()">
function setColor() {
var canvas = document.getElementById("can");
var color = document.getElementById("clr");
canvas.style.backgroundColor = color.value;
}
function doSquare() {
var canvas = document.getElementById("can");
var range = document.getElementById("rng");
var sideL = range.value;
var ctx = canvas.getContext("2d");
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.fillStyle = "yellow";
ctx.fillRect(10,10,sideL, sideL);
ctx.fillRect(sideL + 2,10,sideL, sideL);
}
#can {
width:100px;
height:100px;
border: 1px solid grey;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment