JSFiddle - React, Tailwind, and code Playground
HTML
<div id="content">
<h1 id="h1">Color Picker</h1>
<table id="values">
<tr>
<th>R</th>
<td id="vr"></td>
<th>H</th>
<td id="vh"></td>
<th>H</th>
<td id="vh2"></td>
</tr>
<tr>
<th>G</th>
<td id="vg"></td>
<th>S</th>
<td id="vs"></td>
<th>S</th>
<td id="vs2"></td>
</tr>
<tr>
<th>B</th>
<td id="vb"></td>
<th>B</th>
<td id="vv"></td>
<th>L</th>
<td id="vl"></td>
</tr>
</table>
<input type="text" id="output" value="#eeeeee">
<p id="copy">
Powered by <a href="http://raphaeljs.com/">Raphaël</a>
</p>
<!-- my additions to the example -->
<div id="mydiv1"></div>
<div id="mydiv2"></div>
</div>
<div id="picker2"></div>
CSS
body {
background: #333;
color: #999;
font: 300 100.01%/1.2 "Segoe UI", "Helvetica Neue", Helvetica, "Arial Unicode", Arial, sans-serif;
margin: 0 30px;
}
#content {
width: 640px;
height: 480px;
position: relative;
}
h1 {
font-weight: 300;
font-size: 3em;
position: absolute;
right: 10px;
bottom: 50px;
}
p {
font-size: 2em;
}
#benefits {
margin-top: 350px;
}
#copy a {
color: #666;
text-decoration: none;
}
#picker1 {
width: 300px;
position: absolute;
top: 250px;
left: 50%;
margin-left: -150px;
}
#benefits {
margin-bottom: 0;
}
#output {
background: #eee;
position: absolute;
font-size: 30px;
bottom: 10px;
left: 20px;
font-family: monospace;
margin-top: -20px;
}
#copy {
position: absolute;
right: 10px;
bottom: 10px;
margin: 0;
font-size: .6em;
color: #666;
}
#values {
position: absolute;
left: 20px;
top: 363px;
font-size: .7em;
}
#mydiv1, #mydiv2 {
position: relative;
}
JavaScript
/*!
* Color Picker 0.1.0 - Raphael plugin
*
* Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com)
* Based on Color Wheel (http://jweir.github.com/colorwheel) by John Weir (http://famedriver.com)
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
*/
(function (Raphael) {
Raphael.colorpicker = function (x, y, size, initcolor, element) {
return new ColorPicker(x, y, size, initcolor, element);
};
Raphael.fn.colorPickerIcon = function (x, y, r) {
var segments = pi * r * 2 / Math.min(r / 8, 4);
var a = pi / 2 - pi * 2 / segments * 1.5,
path = ["M", x, y - r, "A", r, r, 0, 0, 1, r * Math.cos(a) + x, y - r * Math.sin(a), "L", x, y, "z"].join();
for (var i = 0; i < segments; i++) {
this.path(path).attr({
stroke: "none",
fill: "hsb(" + (segments - i) * (255 / segments) / 255 + ", 1, 1)",
transform: "r" + [90 + (360 / segments) * i, x, y]
});
}
return this.circle(x, y, r).attr({
fill: "r#fff-#fff",
"fill-opacity": 0,
"stroke-width": Math.round(r * .03),
stroke: "#fff"
});
};
var pi = Math.PI;
function angle(x, y) {
return (x < 0) * 180 + Math.atan(-y / -x) * 180 / pi;
}
var doc = document, win = window,
ColorPicker = function (x, y, size, initcolor, element) {
size = size || 200;
var w3 = 3 * size / 200,
w1 = size / 200,
fi = 1.6180339887,
size20 = size / 20,
size2 = size / 2,
padding = 2 * size / 200,
height = size + size20 * 2 + padding * 3,
t = this,
H = 1, S = 1, B = 1, s = size - (size20 * 4),
r = element ? Raphael(element, size, height) : Raphael(x, y, size, height),
xy = s / 6 + size20 * 2 + padding,
...