diff --git a/index.html b/index.html index a2d1f17..db63bc3 100644 --- a/index.html +++ b/index.html @@ -6,11 +6,16 @@ @@ -18,27 +23,54 @@
Knob demo
-
+
+
+data-width="75"
+data-fgColor="#fff"
+data-skin="tron"
+            
+ +
+
+
+data-width="150"
+data-fgColor="#fff"
+data-skin="tron"
+data-thickness=".2"
+            
+ +
+
+
+data-width="150"
+data-fgColor="#fff"
+data-skin="tron"
+data-thickness=".1"
+            
+ +
+
 data-width="100"
 data-displayInput=false
             
-
+
 data-cursor=true
+data-skin="tron"
             
- +
-
+
 data-width="250"
 data-min="-100"
             
-
+
 data-thickness=".4"
 data-fgColor="chartreuse"
@@ -46,27 +78,41 @@
             
-
+
 data-width="300"
 data-cursor=true
             
-
+
 data-width="200"
             
-
+
 data-width="50"
             
-
+
+ + \ No newline at end of file diff --git a/js/jquery.knob-1.0.1.js b/js/jquery.knob-1.0.1.js index 89de8c7..0d0843e 100644 --- a/js/jquery.knob-1.0.1.js +++ b/js/jquery.knob-1.0.1.js @@ -35,6 +35,7 @@ $(function() { ,'fgColor' : $this.data('fgcolor') || '#87CEEB' //#222222' ,'bgColor' : $this.data('bgcolor') || '#EEEEEE' ,'readOnly' : $this.data('readonly') + ,'skin' : $this.data('skin') || 'default' ,'draw' : /** * @param int a angle @@ -60,16 +61,29 @@ $(function() { ctx.arc( r, r, r-lw, sa, ea, false); ctx.stroke(); - ctx.beginPath(); - ctx.strokeStyle = opt.bgColor; - ctx.arc( - r, r, r-lw ,sa - ,(v==opt.min && !opt.cursor) - ? sa+0.0001 - : ea - , true - ); - ctx.stroke(); + switch(opt.skin){ + + case 'default' : + ctx.beginPath(); + ctx.strokeStyle = opt.bgColor; + ctx.arc( + r, r, r-lw ,sa + ,(v==opt.min && !opt.cursor) + ? sa+0.0001 + : ea + , true + ); + ctx.stroke(); + break; + + case 'tron' : + ctx.lineWidth = 2; + ctx.beginPath(); + ctx.strokeStyle = opt.fgColor; + ctx.arc( r, r, r-lw+1+lw*2/3, 0, 2*Math.PI, false); + ctx.stroke(); + break; + } } ,'change' : /** @@ -79,8 +93,9 @@ $(function() { ,'release' : /** * @param int v Current value + * @param jQuery ipt Input */ - function(v) {} + function(v,ipt) {} } ,gopt ); @@ -104,7 +119,7 @@ $(function() { ,'font-family' : 'Arial' ,'font-weight' : 'bold' ,'text-align' : 'center' - ,'color' : 'lightgrey' + ,'color' : opt.fgColor ,'padding' : '0px' ,'-webkit-appearance': 'none' } @@ -117,13 +132,23 @@ $(function() { ); k = new Knob( c, opt ); - k.onRelease = opt.release; + k.onRelease = function(v) { + opt.release(v,$this); + }; k.val( parseInt($this.val()) || 0 ); k.onChange = function(v) { $this.val(v); opt.change(v); }; + // bind change on input + $this.bind( + 'change' + ,function( e ) { + k.val( $this.val() ); + } + ); + if( !opt.readOnly ){ c.bind( "mousedown touchstart"