Skip to content

Commit 3941062

Browse files
committed
properly prevent parallel animations
1 parent 1f258c5 commit 3941062

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/roundProgress.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ angular.module('angular-svg-round-progress')
3939
var ring = svg.find('path').eq(0);
4040
var background = svg.find('circle').eq(0);
4141
var options = angular.copy(roundProgressConfig);
42-
var lastAnimationId;
42+
var lastAnimationId = 0;
4343
var lastTimeoutId;
4444
var parentChangedListener;
4545

@@ -119,14 +119,14 @@ angular.module('angular-svg-round-progress')
119119
var circleSize = radius - (options.stroke/2) - service.getOffset(element, options);
120120
var elementSize = radius*2;
121121
var isSemicircle = options.semi;
122+
122123
var doAnimation = function(){
123124
// stops some expensive animating if the value is above the max or under 0
124125
if(preventAnimation){
125126
service.updateState(end, max, circleSize, ring, elementSize, isSemicircle);
126127
}else{
127-
$window.cancelAnimationFrame(lastAnimationId);
128-
129128
var startTime = new $window.Date();
129+
var id = ++lastAnimationId;
130130

131131
(function animation(){
132132
var currentTime = $window.Math.min(new Date() - startTime, duration);
@@ -139,8 +139,8 @@ angular.module('angular-svg-round-progress')
139139
elementSize,
140140
isSemicircle);
141141

142-
if(currentTime < duration){
143-
lastAnimationId = $window.requestAnimationFrame(animation);
142+
if(id === lastAnimationId && currentTime < duration){
143+
$window.requestAnimationFrame(animation);
144144
}
145145
})();
146146
}

0 commit comments

Comments
 (0)