I am creating circular counters for surveys by generating a counter for each answer option.
Currently, I am utilizing this "plugin":
Issue:
The problem lies in the plugin not fetching the text value from the <div>
element and failing to draw counters for each div.
Note: It is functioning properly for a single div
Example:
http://jsbin.com/AHUkoBA/3/edit
HTML:
<div class="pollAnswerBar">15</div>
<div class="pollAnswerBar">50</div>
<div class="pollAnswerBar">75</div>
JS:
jQuery(document).ready(function() {
function drawCounter(percent) {
jQuery('div.pollAnswerBar').html('<div class="percent"></div><div id="slice"' + (percent > 50 ? ' class="gt50"' : '') + '><div class="pie"></div>' + (percent > 50 ? '<div class="pie fill"></div>' : '') + '</div>');
var deg = 360 / 100 * percent;
jQuery('#slice .pie').css({
'-moz-transform': 'rotate(' + deg + 'deg)',
'-webkit-transform': 'rotate(' + deg + 'deg)',
'-o-transform': 'rotate(' + deg + 'deg)',
'transform': 'rotate(' + deg + 'deg)'
});
jQuery('.percent').html(Math.round(percent) + '%');
}
jQuery('.pollAnswerBar').each(function() {
var percent = jQuery(this).text();
console.log(percent);
drawCounter(percent);
});
});