You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
3.0 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. jQuery Knob
  2. =============
  3. - canvas based ; no png or jpg sprites.
  4. - touch, mouse and mousewheel, keyboard events implemented.
  5. - downward compatible ; overloads an input element.
  6. Example
  7. -------
  8. ```html
  9. <input type="text" value="75" class="dial">
  10. <script>
  11. $(function() {
  12. $(".dial").knob();
  13. });
  14. </script>
  15. ```
  16. Options
  17. -------
  18. Options are provided as attributes 'data-option':
  19. ```html
  20. <input type="text" class="dial" data-min="-50" data-max="50">
  21. ```
  22. ... or in the "knob()" call :
  23. ```javascript
  24. $(".dial").knob({
  25. 'min':-50,
  26. 'max':50
  27. });
  28. ```
  29. The following options are supported :
  30. Behaviors :
  31. * min : min value | default=0.
  32. * max : max value | default=100.
  33. * step : step size | default=1.
  34. * angleOffset : starting angle in degrees | default=0.
  35. * angleArc : arc size in degrees | default=360.
  36. * stopper : stop at min & max on keydown/mousewheel | default=true.
  37. * readOnly : disable input and events | default=false.
  38. * rotation : direction of progression | default=clockwise.
  39. UI :
  40. * cursor : display mode "cursor", cursor size could be changed passing a numeric value to the option, default width is used when passing boolean value "true" | default=gauge.
  41. * thickness : gauge thickness.
  42. * lineCap : gauge stroke endings. | default=butt, round=rounded line endings
  43. * width : dial width.
  44. * displayInput : default=true | false=hide input.
  45. * displayPrevious : default=false | true=displays the previous value with transparency.
  46. * fgColor : foreground color.
  47. * inputColor : input value (number) color.
  48. * font : font family.
  49. * fontWeight : font weight.
  50. * bgColor : background color.
  51. Hooks
  52. -------
  53. ```html
  54. <script>
  55. $(".dial").knob({
  56. 'release' : function (v) { /*make something*/ }
  57. });
  58. </script>
  59. ```
  60. * 'release' : executed on release
  61. Parameters :
  62. + value : int, current value
  63. * 'change' : executed at each change of the value
  64. Parameters :
  65. + value : int, current value
  66. * 'draw' : when drawing the canvas
  67. Context :
  68. - this.g : canvas context 2D (see Canvas documentation)
  69. - this.$ : jQuery wrapped element
  70. - this.o : options
  71. - this.i : input
  72. - ... console.log(this);
  73. * 'cancel' : triggered on [esc] keydown
  74. * 'format' : allows to format output (add unit %, ms ...)
  75. The scope (this) of each hook function is the current Knob instance (refer to the demo code).
  76. Example
  77. -------
  78. ```html
  79. <input type="text" value="75" class="dial">
  80. <script>
  81. $(".dial").knob({
  82. 'change' : function (v) { console.log(v); }
  83. });
  84. </script>
  85. ```
  86. Dynamically configure
  87. -------
  88. ```html
  89. <script>
  90. $('.dial').trigger(
  91. 'configure',
  92. {
  93. "min":10,
  94. "max":40,
  95. "fgColor":"#FF0000",
  96. "skin":"tron",
  97. "cursor":true
  98. }
  99. );
  100. </script>
  101. ```
  102. Set the value
  103. -------
  104. ```html
  105. <script>
  106. $('.dial')
  107. .val(27)
  108. .trigger('change');
  109. </script>
  110. ```
  111. Supported browser
  112. -------
  113. Tested on Chrome, Safari, Firefox, IE>=8.0 (IE8.0 with excanvas).
  114. ![secretplan](https://raw.github.com/aterrien/jQuery-Knob/master/secretplan.jpg)