forked from aterrien/jQuery-Knob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·306 lines (296 loc) · 13.1 KB
/
index.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<!--[if IE]><script type="text/javascript" src="excanvas.js"></script><![endif]-->
<script src="js/jquery.knob.js"></script>
<script>
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<div style="width:100%;font-size:40px;letter-spacing:-8px;line-height:40px;">
<h1>jQuery Knob</h1>
</div>
<div>
<p>Nice, downward compatible, touchable, jQuery dial. <a href="http://flattr.com/thing/674900/jQuery-Knob" target="_blank"><img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" /></a></p>
<p style="font-size: 20px">* implemented interactions : mouse click and wheel mouse, keyboard (on focus) and fingers (touch events)</p>
</div>
<div class="demo">
<p>× Disable display input</p>
<pre>
data-width="100"
data-displayInput=false
</pre>
<input class="knob" data-width="100" data-displayInput=false value="35">
</div>
<div class="demo">
<p>× 'cursor' mode</p>
<pre>
data-width="150"
data-cursor=true
data-thickness=.3
data-fgColor="#222222"
</pre>
<input class="knob" data-width="150" data-cursor=true data-fgColor="#222222" data-thickness=.3 value="29">
</div>
<div class="demo" >
<p>× Display previous value</p>
<pre>
data-displayPrevious=true
data-min="-100"
</pre>
<input class="knob" data-width="200" data-min="-100" data-displayPrevious=true value="44">
</div>
<div style="clear:both"></div>
<div class="demo">
<p>× Angle offset</p>
<pre>
data-angleOffset=90
data-linecap=round
</pre>
<input class="knob" data-angleOffset=90 data-linecap=round value="35">
</div>
<div class="demo">
<p>× Angle offset and arc</p>
<pre>
data-fgColor="#66CC66"
data-angleOffset=-125
data-angleArc=250
</pre>
<input class="knob" data-angleOffset=-125 data-angleArc=250 data-fgColor="#66EE66" value="35">
</div>
<div class="demo" >
<p>× 5-digit values, step 1000</p>
<pre>
data-step="1000"
data-min="-15000"
data-max="15000"
data-displayPrevious=true
</pre>
<input class="knob" data-min="-15000" data-displayPrevious=true data-max="15000" data-step="1000" value="-11000">
</div>
<div style="clear:both"></div>
<div style="text-align: center">
<p style="font-size: 20px">× Overloaded 'draw' method</p>
</div>
<div style="background-color: #222; height: 340px">
<div class="demo" style="background-color:#222; color:#FFF;">
<pre>
data-width="75"
data-fgColor="#ffec03"
data-skin="tron"
data-thickness=".2"
data-displayPrevious=true
</pre>
<input class="knob" data-width="75" data-displayPrevious=true data-fgColor="#ffec03" data-skin="tron" data-cursor=true value="75" data-thickness=".2">
</div>
<div class="demo" style="background-color:#222; color:#FFF;">
<pre>
data-width="150"
data-fgColor="#ffec03"
data-skin="tron"
data-thickness=".2"
data-displayPrevious=true
</pre>
<input class="knob" data-width="150" data-displayPrevious=true data-fgColor="#ffec03" data-skin="tron" data-thickness=".2" value="75">
</div>
<div class="demo" style="background-color:#222; color:#FFF;">
<pre>
data-width="150"
data-fgColor="#C0ffff"
data-skin="tron"
data-thickness=".1"
data-angleOffset="180"
</pre>
<input class="knob" data-width="150" data-angleOffset="180" data-fgColor="#C0ffff" data-skin="tron" data-thickness=".1" value="35">
</div>
</div>
<div style="clear:both"></div>
<div class="demo" style="width:100%">
<p>× Responsive</p>
<pre>
data-width="80%"
</pre>
<div style="width: 30%; border: 3px dashed; margin-bottom: 20px">
<i>
Current div width is 30% of window width.<br>
Knob width is 80% of current div.<br>
Knob width is 80% of 30% of window width.<br>
Test resizing window.
</i>
<br>
<br>
<input class="knob" data-width="80%" value="35">
</div>
</div>
<div style="clear:both"></div>
<script>
function clock() {
var $s = $(".second"),
$m = $(".minute"),
$h = $(".hour");
d = new Date(),
s = d.getSeconds(),
m = d.getMinutes(),
h = d.getHours();
$s.val(s).trigger("change");
$m.val(m).trigger("change");
$h.val(h).trigger("change");
setTimeout("clock()", 1000);
}
clock();
</script>
<div class="demo" style="color:#EEE;background:#222;height:420px;width:100%">
<p>× Superpose (clock)</p>
<div style="position:relative;width:350px;margin:auto">
<div style="position:absolute;left:10px;top:10px">
<input class="knob hour" data-min="0" data-max="24" data-bgColor="#333" data-fgColor="#ffec03" data-displayInput=false data-width="300" data-height="300" data-thickness=".3">
</div>
<div style="position:absolute;left:60px;top:60px">
<input class="knob minute" data-min="0" data-max="60" data-bgColor="#333" data-displayInput=false data-width="200" data-height="200" data-thickness=".45">
</div>
<div style="position:absolute;left:110px;top:110px">
<input class="knob second" data-min="0" data-max="60" data-bgColor="#333" data-fgColor="rgb(127, 255, 0)" data-displayInput=false data-width="100" data-height="100" data-thickness=".3">
</div>
</div>
</div>
<div style="clear:both"></div>
<div class="demo">
<p>× Readonly</p>
<pre>
readonly (or data-readOnly=true)
data-thickness=".4"
data-fgColor="chartreuse"
</pre>
<input class="knob" data-fgColor="chartreuse" data-thickness=".4" readonly value="22">
</div>
<div class="demo">
<p>× Dynamic</p>
<pre>
data-width="200"
</pre>
<input type="button" onclick="$('.knob-dyn').knob();" value="knobify!">
<input type="text" class="knob-dyn" data-width="200" data-cursor=true value="56">
<pre>
data-width="50"
data-cursor=true
</pre>
<input type="button" onclick="$('.knob-dyn2').knob();" value="knobify!">
<input type="text" class="knob-dyn2" data-width="50" data-thickness=".4" value="56">
</div>
<div class="demo" style="height:440px;width:300px">
<p>× Infinite || iPod click wheel</p>
<div style="float:left;width:180px;height:320px;padding:20px;background-color:#EEEEEE;text-align:center;">
<pre>
data-width="150"
data-cursor=true
data-thickness=".5"
data-fgColor="#AAAAAA"
data-bgColor="#FFFFFF"
data-displayInput="false"
+ some code
</pre>
<input class="infinite" data-width="150" data-thickness=".5" data-fgColor="#AAAAAA" data-bgColor="#FFFFFF" data-displayInput="false" data-cursor=true>
</div>
<div style="float:left;margin-top:200px;">
<div class="ival" style="width:80px;text-align:center;font-size:50px;color:#AAA">0</div>
<div class="idir" style="width:80px;text-align:center;font-size:50px;"></div>
</div>
</div>
<div style="clear:both"></div>
<div style="margin-top:30px;text-align:center">
<img src="https://raw.github.com/aterrien/jQuery-Knob/master/secretplan.jpg">
<p style="font-size:20px;">jQuery Knob is © 2012 Anthony Terrien - MIT License</p>
</div>
</body>
</html>