Created
December 16, 2011 11:58
-
-
Save akheron/1485792 to your computer and use it in GitHub Desktop.
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
/* JavaScript progress bar | |
* | |
* Reads the percentage value from the content of an element and | |
* replaces it with a progress bar. | |
* | |
* Example: | |
* | |
* <span class="progress">100 %</span> | |
* <script> | |
* $('.progress').progressbar(); | |
* </script> | |
*/ | |
(function($) { | |
$.fn.progressbar = function(options) { | |
var defaults = { | |
color: '#07f' | |
}; | |
options = $.extend({}, defaults, options); | |
this.each(function() { | |
var text = $(this).html().replace('%', '').replace(/\s+/g, ''), | |
progress = parseFloat(text) / 10 | 0, | |
span = '<span> </span> ', | |
content = new Array(11).join(span); | |
$(this).html(content) | |
.find(':lt(' + progress + ')') | |
.css('background-color', options.color); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment