<html>
<head>
<title>COLOUR</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="json.js"></script>
</head>
<body>
<h2 id ="colordisplay">#000000</h2>
<form name="myform">
<label for="name">Name</label>
<input type="text" id="name" name="name" value=""/>
<label for="red">RED</label>
<input type="range" min="0" max="255" step="1"
value="0" id="red" name="red" onchange="changeColors()"/>
<label for="green">Green</label>
<input type="range" min="0" max="255" step="1"
value="0" id="green" name="green" onchange="changeColors()"/>
<label for="blue">Blue</label>
<input type="range" min="0" max="255" step="1"
value="0" id="blue" name="blue" onchange="changeColors()"/>
<label for="opacity">Alpha</label>
<input type="range" min="0" max="1" step="0.1"
value="1" id="opacity" name="opacity" onchange="changeColors()"/>
<input name="button1" type="button" value="Save" onclick="Save()"/>
<select id="selectColor">
<option></option>
</select>
<input name="button2" type="button" value="Place" onclick="Place();"/>
<input name="button3" type="button" value="Remove" onclick="Remove();"/>
</form>
<div id="div"><div>
</body>
function changeColors() {
//get the numbers from the html
var rd = parseInt(document.getElementById("red").value);
var gr = parseInt(document.getElementById("green").value);
var bl = parseInt(document.getElementById("blue").value);
var op = parseFloat(document.getElementById("opacity").value);
//convert the decimal into hexadecimal
var rdhex = (rd < 16) ? "0" + rd.toString(16) : rd.toString(16);
var grhex = (gr < 16) ? "0" + gr.toString(16) : gr.toString(16);
var blhex = (bl < 16) ? "0" + bl.toString(16) : bl.toString(16);
//concatenate all hex to generate a color
var hexcode = "#" + rdhex + grhex + blhex;
//set the background of the div
setColor(hexcode, op);
}
function setColor(hexcode, opacity) {
//view the change in the browser
document.getElementById("div").style.backgroundColor = hexcode;
document.getElementById("colordisplay").innerHTML = hexcode;
//change opacity
document.getElementById("div").style.opacity = opacity;
}
var colors = [];
function Save() {
var name = document.getElementById("name").value;
var rgb = document.getElementById("colordisplay").innerHTML;
var opacity = document.getElementById("div").style.opacity;
colors.push({
name_prop:name,
rgb_prop:rgb,
opacity_prop:opacity
});
//pass the object to the drop down list
var select = document.getElementById("selectColor");
var opt = name;
var el = document.createElement("option");
el.innerHTML = opt;
el.value = opt;
select.appendChild(el);
console.log(colors);
}
function Place() {
var select = document.getElementById("selectColor");
colors.forEach(function(colorObject) {
if (colorObject.name_prop == select.value) {
setColor(colorObject.rgb_prop, colorObject.opacity_prop);
}
});
}
function Remove () {
var select = document.getElementById("selectColor");
for(var i = 0; i < colors.length; i --) {
var selectIndex = colors.indexOf(select.value);
if(selectIndex !== -1){
colors.splice(i, 1);
}
return false;
}
}
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |