A Pen by Justin Shi on CodePen.
Last active
August 5, 2020 02:35
-
-
Save RshStone/474b8ced5dea9a175b418f1c2ff2c5cb to your computer and use it in GitHub Desktop.
Inputs and Events
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
<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> | |
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 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); | |
} |
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
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