Skip to content

Commit 44284db

Browse files
committed
Merge pull request #3 from sebastienbarre/seb/quick_changes
Seb/quick changes
2 parents 7c3d827 + 29b1172 commit 44284db

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ you can set the options easily as data attributes for Example: data-dimension="2
5454
* icon / Fontawesome icon class without the fa- before the class for example not fa-plus just plus
5555
* icon-size / Will set the font size of the icon.
5656
* icon-color / Will set the font color of the icon.
57+
* animation-step / Will set the animation step, use 0 to disable animation, 0.5 to slow down, 2 to speed up, etc / default is 1
5758

5859

5960
Examples

js/jquery.circliful.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
// These are the defaults.
77
foregroundColor: "#556b2f",
88
backgroundColor: "#eee",
9+
fillColor: false,
910
width: 15,
1011
dimension: 200,
1112
size: 15,
12-
percent: 50
13+
percent: 50,
14+
animationStep: 1.0
1315
}, options );
1416
return this.each(function() {
1517
var dimension = '';
@@ -22,8 +24,9 @@
2224
var fgcolor = '';
2325
var bgcolor = '';
2426
var icon = '';
27+
var animationstep = 0.0;
2528

26-
$(this).attr('class', 'circliful');
29+
$(this).addClass('circliful');
2730

2831
if($(this).data('dimension') != undefined) {
2932
dimension = $(this).data('dimension');
@@ -61,7 +64,12 @@
6164
} else {
6265
bgcolor = settings.backgroundColor;
6366
}
64-
67+
68+
if($(this).data('animation-step') != undefined) {
69+
animationstep = parseFloat($(this).data('animation-step'));
70+
} else {
71+
animationstep = settings.animationStep;
72+
}
6573
if($(this).data('text') != undefined) {
6674
text = $(this).data('text');
6775

@@ -108,10 +116,7 @@
108116

109117
$(this).width(dimension + 'px');
110118

111-
$(this).append('<canvas id="' + $(this).attr('id') + '_canvas" width="' + dimension + '" height="' + dimension + '"></canvas>');
112-
113-
114-
var canvas = document.getElementById($(this).attr('id') + '_canvas');
119+
var canvas = $('<canvas></canvas>').attr({ width: dimension, height: dimension }).appendTo($(this)).get(0);
115120
var context = canvas.getContext('2d');
116121
var x = canvas.width / 2;
117122
var y = canvas.height / 2;
@@ -121,7 +126,8 @@
121126
var startAngle = 2.3 * Math.PI;
122127
var endAngle = 0;
123128
var counterClockwise = false;
124-
var curPerc = 0;
129+
var curPerc = animationstep === 0.0 ? endPercent : 0.0;
130+
var curStep = Math.max(animationstep, 0.0);
125131
var circ = Math.PI * 2;
126132
var quart = Math.PI / 2;
127133
var type = '';
@@ -140,8 +146,9 @@
140146

141147
if($(this).data('fill') != undefined) {
142148
fill = $(this).data('fill');
149+
} else {
150+
fill = settings.fillColor;
143151
}
144-
145152
//animate foreground circle
146153
function animate(current) {
147154
context.clearRect(0, 0, canvas.width, canvas.height);
@@ -165,17 +172,17 @@
165172
// line color
166173
context.strokeStyle = fgcolor;
167174
context.stroke();
168-
curPerc++;
169-
170-
if (curPerc <= endPercent) {
175+
176+
if (curPerc < endPercent) {
177+
curPerc += curStep;
171178
requestAnimationFrame(function () {
172-
animate(curPerc / 100);
179+
animate(Math.min(curPerc, endPercent) / 100);
173180
});
174181
}
175182

176183
}
177-
178-
animate();
184+
185+
animate(curPerc / 100);
179186

180187
});
181188

js/jquery.circliful.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)