Permalink
Browse files

adding support for mousewheel and arrow keys

  • Loading branch information...
eskimoblood committed May 10, 2012
1 parent 7a4f59c commit de49560e1426e76913c4e99424224cc1fd538102
Showing with 20 additions and 0 deletions.
  1. +20 −0 js/jquery.knob-1.0.1.js
View
@@ -116,6 +116,7 @@ $(function() {
}
);
+
k = new Knob( c, opt );
k.onRelease = opt.release;
k.val( parseInt($this.val()) || 0 );
@@ -135,6 +136,25 @@ $(function() {
}else{
$this.attr('readonly','readonly');
}
+
+ var keys={37: -1, 38:1, 39:1, 40: -1}
+
+ $this.keydown(function(event){
+ setVal( keys[event.keyCode])
+ });
+
+ $this.bind('mousewheel DOMMouseScroll', function(event){
+ var deltaX = event.originalEvent.wheelDeltaX;
+ var deltaY = event.originalEvent.wheelDeltaY;
+ event.preventDefault();
+ setVal( deltaX > 0 || deltaY > 0 ? 1 : deltaX < 0 || deltaY < 0 ? -1 : 0)
+ });
+
+ function setVal(dir){
+ if(dir){
+ k.val( parseInt($this.val()) + dir )
+ }
+ }
}
).parent();
}

0 comments on commit de49560

Please sign in to comment.