Last active
August 29, 2015 14:24
-
-
Save leolovenet/f5a8d359100b7726dff5 to your computer and use it in GitHub Desktop.
jQuery Knob draw with animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by [email protected] on 7/2/15. | |
*/ | |
(function(){ | |
"use strict"; | |
var Circles = function(e,op) { | |
this.options = $.extend({}, Circles.DEFAULTS, op); | |
this.$e = $(e); | |
this.$e.val(this.options.to); | |
this.$e.knob(this.options); | |
this.inited = false; | |
if (this.options.animation) { | |
this.animationDraw(); | |
} | |
}; | |
Circles.DEFAULTS = { | |
readOnly:true, | |
fgColor:'#6DB311', | |
width:"85%", | |
from:0, | |
to:100, | |
animation:true | |
}; | |
Circles.prototype.animationDraw = function(){ | |
var _this = this,v; | |
if(!_this.inited){ | |
_this.$e.val(_this.options.from); | |
v = _this.options.from; | |
_this.inited = true; | |
}else{ | |
v = _this.$e.val(); | |
} | |
if(v>=_this.options.to){ | |
_this.inited = false; | |
return; | |
} | |
v=parseInt(v)+1; | |
_this.$e.val(v).trigger('change'); | |
setTimeout($.proxy(this.animationDraw,this),10); | |
}; | |
$.fn.circle = function(option) { | |
return this.each(function(){ | |
var $this = $(this); | |
var data = $this.data('circle'); | |
var options = typeof option == 'object' && option; | |
if (!data) { | |
$this.data('circle', (data = new Circles(this, options || {}))); | |
} | |
if ( option == 'redraw') { | |
data.animationDraw(); | |
} | |
}); | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title>test</title> | |
<script type="text/javascript" src="./js/jquery.js"></script> | |
<script type="text/javascript" src="./js/jquery.knob.js"></script> | |
<script type="text/javascript" src="./js/jquery.circle.js"></script> | |
</head> | |
<body> | |
<input type="text" value="0" class="dial" > | |
<script> | |
$(function() { | |
$(".dial").circle({to:75}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment