forked from manicken/manicken.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjscolor-examples.html
151 lines (87 loc) · 3.32 KB
/
jscolor-examples.html
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
147
148
149
150
151
<!DOCTYPE html>
<html lang="en">
<head>
<title>jscolor Examples</title>
<style>
body { padding: 30px 60px 30px; }
h2, footer { margin: 150px 0 20px; }
footer h2 { margin: 30px 0 15px; }
</style>
</head>
<body>
<h1>Examples of <a href="https://jscolor.com/" target="_blank">jscolor</a> usage</h1>
<script src="jscolor.js"></script>
<h2>Example 1 - RGBA</h2>
Color: <input value="rgba(40,170,255,0.5)" data-jscolor="">
<h2>Example 2 - HEX</h2>
Color: <input value="2CAFFE" data-jscolor="">
<h2>Example 3 - HEX with Alpha</h2>
Color: <input value="2CAFFE" data-jscolor="{alphaElement:'#alp3'}">
Alpha: <input id="alp3" value="0.5">
<h2>Example 4 - Button</h2>
Color: <button data-jscolor="{valueElement:'#val4', alphaElement:'#alp4'}"></button>
Value: <input id="val4" value="rgba(170,35,100,0.5)">
Alpha: <input id="alp4">
<h2>Example 5 - Events: onChange and onInput</h2>
<p>
You can specify onChange/onInput event handler using jscolor's options:
<button data-jscolor="{
onChange: 'update(this, \'#pr1\')',
onInput: 'update(this, \'#pr2\')',
alpha:0.7, value:'CCFFAA'}"></button>
</p>
<em id="pr1" style="display:inline-block; padding:1em;">change event</em>
<em id="pr2" style="display:inline-block; padding:1em;">input event</em>
<p>
For text INPUTS, you can keep with classic HTML attributes:
<input onChange="update(this.jscolor, '#pr3')" onInput="update(this.jscolor, '#pr4')" value="CCFFAA" data-jscolor="{alpha:0.7}">
</p>
<em id="pr3" style="display:inline-block; padding:1em;">change event</em>
<em id="pr4" style="display:inline-block; padding:1em;">input event</em>
<script>
function update(picker, selector) {
document.querySelector(selector).style.background = picker.toBackground()
}
// triggers 'onInput' and 'onChange' on all color pickers when they are ready
jscolor.trigger('input change');
</script>
<h2>Example 6 - Presets</h2>
<p>
Small dark preset:
<input value="FFA000" data-jscolor="{preset:'small dark', position:'right'}">
</p>
<p>
Large preset:
<input value="rgba(255,160,0,0.5)" data-jscolor="{preset:'large', position:'right'}">
</p>
<h2>Example 7 - Custom theme</h2>
<input value="rgba(255,160,0,0.5)" data-jscolor="{
position: 'right', width: 181, height: 181,
padding: 10, sliderSize: 25, borderRadius: 5,
borderWidth: 1, controlBorderWidth: 1, pointerBorderWidth: 2,
borderColor: '#000', controlBorderColor: '#CCC', backgroundColor: '#333'
}">
<!-- HINT: To set defaults for all pickers, use variable jscolor.presets.default
<script>
jscolor.presets.default = {
position: 'right', width: 181, height: 181,
padding: 10, sliderSize: 25, borderRadius: 5,
borderWidth: 1, controlBorderWidth: 1, pointerBorderWidth: 2,
borderColor: '#000', controlBorderColor: '#CCC', backgroundColor: '#333'
};
</script>
-->
<footer>
<h2>Links</h2>
<ul>
<li><a href="https://jscolor.com/examples/" target="_blank">More examples</a></li>
<li><a href="https://jscolor.com/docs/" target="_blank">Documentation</a></li>
</ul>
<h2>License</h2>
<ul>
<li><a href="http://www.gnu.org/licenses/gpl-3.0.txt" target="_blank">GNU GPL v3</a> for open source use</li>
<li><a href="https://jscolor.com/download/#licenses" target="_blank">Commercial license</a> for commercial use</li>
</ul>
</footer>
</body>
</html>