-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcolorpicker-demo.html
More file actions
146 lines (132 loc) · 4.96 KB
/
Copy pathcolorpicker-demo.html
File metadata and controls
146 lines (132 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html>
<head>
<title>
colorpicker in HTML 5 canvas and javascript (no jquery)
</title>
<style>
/*force IE to not scroll the page to be able to change the handles on a touch device*/
canvas{
-ms-touch-action: none;
}
a{
display:block;
border: 1px solid gray;
width: auto;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1" />
</head>
<body>
<h1>
html5-colorPicker
================
</h1><p>
<br />
</p>
<a href="jeroen.vanoorschot.biz">Jeroen van Oorschot</a><br /><a href="https://github.com/JeroenvO/html5-colorpicker"><img src="GitHub_Logo.png" width="80px">github code</a>
<br /><br />
<a href="https://github.com/JeroenvO/html5-timepicker"><img src="GitHub_Logo.png" width="80px">Also view my html5 canvas timepicker/clock</a>
<br />
<script type="text/javascript" src="colorPicker.js"></script>
<div>
<h2>Colorpicker</h2>
<p>
<!-- don't forget this part -->
<!-- Definition of the canvas objects-->
<canvas width="500" height="500" id="colorPicker1"></canvas>
</div>
<!--an example division to show the color of the colorpicker -->
The onColorChange callback function updates the color in the below box
<br />
<span id='colorPickerValue'>--color appears here on change--</span>
</p><p>
<!-- colorpicker without value-->
<h2>A colorpicker without the value ring by setting "nov:true"</h2>
<br />
<canvas width="500" height="500" id="colorPicker2"></canvas>
</p>
<script>
/*
## options ##
* h -> initial color hue
* s -> initial color saturation
* v -> initial color value
* image -> the image to use for the background. Default is color-500.png
* centerX, centerY -> define a custom center position for the colorpicker. The center of the canvas is default
* drawInterval -> number of milliseconds between drawing. default is 10ms = 100hz. The real speed depends on the browser and computer.
* scale -> set the scale of the colorpicker. This is the number of pixels the arc for value is thick. When not set, it adapts to the canvas size: scale = min(w,h) / 10.
## functions ##
* onColorChange -> callback on dragging the handles
* onCenterClick -> callback on clicking on the center
to set options after creating the colorpicker use these functions.
* [name].setColorHSV(h,s,v) ->to set the color to a hsv value
to retrieve values at any moment use
* [name].getColorHSV() to get the color in HSV
* [name].getColorHSL() to get the color in HSL (for use in CSS colors)
*/
//add the colorpicker to the canvas
colorPicker1 = new colorPicker(document.getElementById('colorPicker1'), {
bgcolor: 'rgba(50,50,50,0)',
onColorChange: function(){
var color = this.getColorHSV();
document.getElementById('colorPickerValue').innerHTML = "Color h:"+color.h+" s: "+ color.s+" v: "+ color.v;
},
onCenterClick: function(){
window.alert('You clicked the center!');
}
});
//add the colorpicker to the canvas
colorPicker2 = new colorPicker(document.getElementById('colorPicker2'), {
bgcolor: 'rgba(50,50,50,0)',
nov: true,
onCenterClick: function(){
window.alert('You clicked the center of colorpicker 2!');
}
});
</script>
<p>
Use 'view-source' for more information or view on github.
<br />
<textarea cols=80 rows=40>
/*
## options ##
* h -> initial color hue
* s -> initial color saturation
* v -> initial color value
* image -> the image to use for the background. Default is color-500.png
* centerX, centerY -> define a custom center position for the colorpicker. The center of the canvas is default
* drawInterval -> number of milliseconds between drawing. default is 10ms = 100hz. The real speed depends on the browser and computer.
* scale -> set the scale of the colorpicker. This is the number of pixels the arc for value is thick. When not set, it adapts to the canvas size: scale = min(w,h) / 10.
## functions ##
* onColorChange -> callback on dragging the handles
* onCenterClick -> callback on clicking on the center
to set options after creating the colorpicker use these functions.
* [name].setColorHSV(h,s,v) ->to set the color to a hsv value
to retrieve values at any moment use
* [name].getColorHSV() to get the color in HSV
* [name].getColorHSL() to get the color in HSL (for use in CSS colors)
*/
//add the colorpicker to the canvas
colorPicker1 = new colorPicker(document.getElementById('colorPicker1'), {
bgcolor: 'rgba(50,50,50,0)',
onColorChange: function(){
var color = this.getColorHSV();
document.getElementById('colorPickerValue').innerHTML = "Color h:"+color.h+" s: "+ color.s+" v: "+ color.v;
},
onCenterClick: function(){
window.alert('You clicked the center!');
}
});
//add the colorpicker to the canvas
colorPicker2 = new colorPicker(document.getElementById('colorPicker2'), {
bgcolor: 'rgba(50,50,50,0)',
nov: true,
onCenterClick: function(){
window.alert('You clicked the center of colorpicker 2!');
}
});
</textarea>
</p>
</body>
</html>