index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>jQuery Knob demo</title>
  5. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
  6. <!--[if IE]><script type="text/javascript" src="excanvas.js"></script><![endif]-->
  7. <script src="dist/jquery.knob.min.js"></script>
  8. <script>
  9. $(function($) {
  10. $(".knob").knob({
  11. change : function (value) {
  12. //console.log("change : " + value);
  13. },
  14. release : function (value) {
  15. //console.log(this.$.attr('value'));
  16. console.log("release : " + value);
  17. },
  18. cancel : function () {
  19. console.log("cancel : ", this);
  20. },
  21. /*format : function (value) {
  22. return value + '%';
  23. },*/
  24. draw : function () {
  25. // "tron" case
  26. if(this.$.data('skin') == 'tron') {
  27. this.cursorExt = 0.3;
  28. var a = this.arc(this.cv) // Arc
  29. , pa // Previous arc
  30. , r = 1;
  31. this.g.lineWidth = this.lineWidth;
  32. if (this.o.displayPrevious) {
  33. pa = this.arc(this.v);
  34. this.g.beginPath();
  35. this.g.strokeStyle = this.pColor;
  36. this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, pa.s, pa.e, pa.d);
  37. this.g.stroke();
  38. }
  39. this.g.beginPath();
  40. this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
  41. this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, a.s, a.e, a.d);
  42. this.g.stroke();
  43. this.g.lineWidth = 2;
  44. this.g.beginPath();
  45. this.g.strokeStyle = this.o.fgColor;
  46. this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
  47. this.g.stroke();
  48. return false;
  49. }
  50. }
  51. });
  52. // Example of infinite knob, iPod click wheel
  53. var v, up=0,down=0,i=0
  54. ,$idir = $("div.idir")
  55. ,$ival = $("div.ival")
  56. ,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
  57. ,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
  58. $("input.infinite").knob(
  59. {
  60. min : 0
  61. , max : 20
  62. , stopper : false
  63. , change : function () {
  64. if(v > this.cv){
  65. if(up){
  66. decr();
  67. up=0;
  68. }else{up=1;down=0;}
  69. } else {
  70. if(v < this.cv){
  71. if(down){
  72. incr();
  73. down=0;
  74. }else{down=1;up=0;}
  75. }
  76. }
  77. v = this.cv;
  78. }
  79. });
  80. });
  81. </script>
  82. <style>
  83. body{
  84. padding: 0;
  85. margin: 0px 50px;
  86. font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  87. font-weight: 300;
  88. text-rendering: optimizelegibility;
  89. }
  90. p{font-size: 30px; line-height: 30px}
  91. div.demo{text-align: center; width: 280px; float: left}
  92. div.demo > p{font-size: 20px}
  93. </style>
  94. </head>
  95. <body>
  96. <div style="width:100%;font-size:40px;letter-spacing:-8px;line-height:40px;">
  97. <h1>jQuery Knob</h1>
  98. </div>
  99. <div>
  100. <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>
  101. <p style="font-size: 20px">* implemented interactions : mouse click and wheel mouse, keyboard (on focus) and fingers (touch events)</p>
  102. </div>
  103. <div class="demo">
  104. <p>&#215; Disable display input</p>
  105. <pre>
  106. data-width="100"
  107. data-displayInput=false
  108. </pre>
  109. <input class="knob" data-width="100" data-displayInput=false value="35">
  110. </div>
  111. <div class="demo">
  112. <p>&#215; 'cursor' mode</p>
  113. <pre>
  114. data-width="150"
  115. data-cursor=true
  116. data-thickness=.3
  117. data-fgColor="#222222"
  118. </pre>
  119. <input class="knob" data-width="150" data-cursor=true data-fgColor="#222222" data-thickness=.3 value="29">
  120. </div>
  121. <div class="demo" >
  122. <p>&#215; Display previous value</p>
  123. <pre>
  124. data-displayPrevious=true
  125. data-min="-100"
  126. </pre>
  127. <input class="knob" data-width="200" data-min="-100" data-displayPrevious=true value="44">
  128. </div>
  129. <div style="clear:both"></div>
  130. <div class="demo">
  131. <p>&#215; Angle offset</p>
  132. <pre>
  133. data-angleOffset=90
  134. data-linecap=round
  135. </pre>
  136. <input class="knob" data-angleOffset=90 data-linecap=round value="35">
  137. </div>
  138. <div class="demo">
  139. <p>&#215; Angle offset and arc</p>
  140. <pre>
  141. data-fgColor="#66CC66"
  142. data-angleOffset=-125
  143. data-angleArc=250
  144. data-rotation=anticlockwise
  145. </pre>
  146. <input class="knob" data-angleOffset=-125 data-angleArc=250 data-fgColor="#66EE66" data-rotation="anticlockwise" value="35">
  147. </div>
  148. <div class="demo" >
  149. <p>&#215; 4-digit, step 0.1</p>
  150. <pre>
  151. data-step=".1"
  152. data-min="-10000"
  153. data-max="10000"
  154. value="0"
  155. data-displayPrevious=true
  156. </pre>
  157. <input class="knob" data-min="-10000" data-displayPrevious=true data-max="10000" data-step=".1" value="0">
  158. </div>
  159. <div style="clear:both"></div>
  160. <div style="text-align: center">
  161. <p style="font-size: 20px">&#215; Overloaded 'draw' method</p>
  162. </div>
  163. <div style="background-color: #222; height: 340px">
  164. <div class="demo" style="background-color:#222; color:#FFF;">
  165. <pre>
  166. data-width="75"
  167. data-fgColor="#ffec03"
  168. data-skin="tron"
  169. data-thickness=".2"
  170. data-displayPrevious=true
  171. </pre>
  172. <input class="knob" data-width="75" data-displayPrevious=true data-fgColor="#ffec03" data-skin="tron" data-cursor=true value="75" data-thickness=".2">
  173. </div>
  174. <div class="demo" style="background-color:#222; color:#FFF;">
  175. <pre>
  176. data-width="150"
  177. data-fgColor="#ffec03"
  178. data-skin="tron"
  179. data-thickness=".2"
  180. data-displayPrevious=true
  181. </pre>
  182. <input class="knob" data-width="150" data-displayPrevious=true data-fgColor="#ffec03" data-skin="tron" data-thickness=".2" value="75">
  183. </div>
  184. <div class="demo" style="background-color:#222; color:#FFF;">
  185. <pre>
  186. data-width="150"
  187. data-fgColor="#C0ffff"
  188. data-skin="tron"
  189. data-thickness=".1"
  190. data-angleOffset="180"
  191. </pre>
  192. <input class="knob" data-width="150" data-angleOffset="180" data-fgColor="#C0ffff" data-skin="tron" data-thickness=".1" value="35">
  193. </div>
  194. </div>
  195. <div style="clear:both"></div>
  196. <div class="demo" style="width:100%">
  197. <p>&#215; Responsive</p>
  198. <pre>
  199. data-width="80%"
  200. </pre>
  201. <div style="width: 30%; border: 3px dashed; margin-bottom: 20px">
  202. <i>
  203. Current div width is 30% of window width.<br>
  204. Knob width is 80% of current div.<br>
  205. Knob width is 80% of 30% of window width.<br>
  206. Test resizing window.
  207. </i>
  208. <br>
  209. <br>
  210. <input class="knob" data-width="80%" value="35">
  211. </div>
  212. </div>
  213. <div style="clear:both"></div>
  214. <script>
  215. function clock() {
  216. var $s = $(".second"),
  217. $m = $(".minute"),
  218. $h = $(".hour");
  219. d = new Date(),
  220. s = d.getSeconds(),
  221. m = d.getMinutes(),
  222. h = d.getHours();
  223. $s.val(s).trigger("change");
  224. $m.val(m).trigger("change");
  225. $h.val(h).trigger("change");
  226. setTimeout("clock()", 1000);
  227. }
  228. clock();
  229. </script>
  230. <div class="demo" style="color:#EEE;background:#222;height:420px;width:100%">
  231. <p>&#215; Superpose (clock)</p>
  232. <div style="position:relative;width:350px;margin:auto">
  233. <div style="position:absolute;left:10px;top:10px">
  234. <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">
  235. </div>
  236. <div style="position:absolute;left:60px;top:60px">
  237. <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">
  238. </div>
  239. <div style="position:absolute;left:110px;top:110px">
  240. <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">
  241. </div>
  242. </div>
  243. </div>
  244. <div style="clear:both"></div>
  245. <div class="demo">
  246. <p>&#215; Readonly</p>
  247. <pre>
  248. readonly (or data-readOnly=true)
  249. data-thickness=".4"
  250. data-fgColor="chartreuse"
  251. </pre>
  252. <input class="knob" data-fgColor="chartreuse" data-thickness=".4" readonly value="22">
  253. </div>
  254. <div class="demo">
  255. <p>&#215; Dynamic</p>
  256. <pre>
  257. data-width="200"
  258. </pre>
  259. <input type="button" onclick="$('.knob-dyn').knob();" value="knobify!">
  260. <input type="text" class="knob-dyn" data-width="200" data-cursor=true value="56">
  261. <pre>
  262. data-width="50"
  263. data-cursor=true
  264. </pre>
  265. <input type="button" onclick="$('.knob-dyn2').knob();" value="knobify!">
  266. <input type="text" class="knob-dyn2" data-width="50" data-thickness=".4" value="56">
  267. </div>
  268. <div class="demo" style="height:440px;width:300px">
  269. <p>&#215; Infinite || iPod click wheel</p>
  270. <div style="float:left;width:180px;height:320px;padding:20px;background-color:#EEEEEE;text-align:center;">
  271. <pre>
  272. data-width="150"
  273. data-cursor=true
  274. data-thickness=".5"
  275. data-fgColor="#AAAAAA"
  276. data-bgColor="#FFFFFF"
  277. data-displayInput="false"
  278. + some code
  279. </pre>
  280. <input class="infinite" value="0" data-width="150" data-thickness=".5" data-fgColor="#AAAAAA" data-bgColor="#FFFFFF" data-displayInput="false" data-cursor=true>
  281. </div>
  282. <div style="float:left;margin-top:200px;">
  283. <div class="ival" style="width:80px;text-align:center;font-size:50px;color:#AAA">0</div>
  284. <div class="idir" style="width:80px;text-align:center;font-size:50px;"></div>
  285. </div>
  286. </div>
  287. <div style="clear:both"></div>
  288. <div style="margin-top:30px;text-align:center">
  289. <img src="https://raw.github.com/aterrien/jQuery-Knob/master/secretplan.jpg">
  290. <p style="font-size:20px;">jQuery Knob is &copy; 2012 Anthony Terrien - MIT License</p>
  291. </div>
  292. </body>
  293. </html>