A Pen by Theodore Rand on CodePen.
Created
July 23, 2017 14:32
-
-
Save tedrand/efe968c5593c6a9201808059ba8983b0 to your computer and use it in GitHub Desktop.
Inputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Working with Input Types</h1> | |
<canvas id="can"></canvas> | |
<input id="clr" type="color" | |
onchange="setColor()"> | |
<input id="rng" type="range" | |
onchange="doSquare()"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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