Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit a4b9a6a

Browse files
matskomhevery
authored andcommitted
fix($animator): ensure $animator calculates the highest duration + delay for and transitions and animations together
1 parent a2f9e78 commit a4b9a6a

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

src/ng/animator.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -345,28 +345,29 @@ var $AnimatorProvider = function() {
345345
var ELEMENT_NODE = 1;
346346
forEach(element, function(element) {
347347
if (element.nodeType == ELEMENT_NODE) {
348-
var w3cProp = w3cTransitionProp,
349-
vendorProp = vendorTransitionProp,
350-
iterations = 1,
351-
elementStyles = $window.getComputedStyle(element) || {};
348+
var elementStyles = $window.getComputedStyle(element) || {};
352349

353-
//use CSS Animations over CSS Transitions
354-
if(parseFloat(elementStyles[w3cAnimationProp + durationKey]) > 0 ||
355-
parseFloat(elementStyles[vendorAnimationProp + durationKey]) > 0) {
356-
w3cProp = w3cAnimationProp;
357-
vendorProp = vendorAnimationProp;
358-
iterations = Math.max(parseInt(elementStyles[w3cProp + animationIterationCountKey]) || 0,
359-
parseInt(elementStyles[vendorProp + animationIterationCountKey]) || 0,
360-
iterations);
361-
}
350+
var transitionDelay = Math.max(parseMaxTime(elementStyles[w3cTransitionProp + delayKey]),
351+
parseMaxTime(elementStyles[vendorTransitionProp + delayKey]));
352+
353+
var animationDelay = Math.max(parseMaxTime(elementStyles[w3cAnimationProp + delayKey]),
354+
parseMaxTime(elementStyles[vendorAnimationProp + delayKey]));
362355

363-
var parsedDelay = Math.max(parseMaxTime(elementStyles[w3cProp + delayKey]),
364-
parseMaxTime(elementStyles[vendorProp + delayKey]));
356+
var transitionDuration = Math.max(parseMaxTime(elementStyles[w3cTransitionProp + durationKey]),
357+
parseMaxTime(elementStyles[vendorTransitionProp + durationKey]));
365358

366-
var parsedDuration = Math.max(parseMaxTime(elementStyles[w3cProp + durationKey]),
367-
parseMaxTime(elementStyles[vendorProp + durationKey]));
359+
var animationDuration = Math.max(parseMaxTime(elementStyles[w3cAnimationProp + durationKey]),
360+
parseMaxTime(elementStyles[vendorAnimationProp + durationKey]));
361+
362+
if(animationDuration > 0) {
363+
animationDuration *= Math.max(parseInt(elementStyles[w3cAnimationProp + animationIterationCountKey]) || 0,
364+
parseInt(elementStyles[vendorAnimationProp + animationIterationCountKey]) || 0,
365+
1);
366+
}
368367

369-
duration = Math.max(parsedDelay + (iterations * parsedDuration), duration);
368+
duration = Math.max(animationDelay + animationDuration,
369+
transitionDelay + transitionDuration,
370+
duration);
370371
}
371372
});
372373
$window.setTimeout(done, duration * 1000);

test/ng/animatorSpec.js

+27
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,33 @@ describe("$animator", function() {
666666
expect(element[0].style.display).toBe('');
667667
}));
668668

669+
it("should select the highest duration and delay",
670+
inject(function($animator, $rootScope, $compile, $sniffer) {
671+
var styles = 'transition:1s linear all 2s;' +
672+
vendorPrefix + 'transition:1s linear all 2s;' +
673+
'animation:my_ani 10s 1s;' +
674+
vendorPrefix + 'animation:my_ani 10s 1s;';
675+
676+
element = $compile(html('<div style="' + styles + '">foo</div>'))($rootScope);
677+
678+
var animator = $animator($rootScope, {
679+
ngAnimate : '{show: \'inline-show\'}'
680+
});
681+
682+
element.css('display','none');
683+
expect(element.css('display')).toBe('none');
684+
685+
animator.show(element);
686+
if ($sniffer.transitions) {
687+
window.setTimeout.expect(1).process();
688+
window.setTimeout.expect(11000).process();
689+
}
690+
else {
691+
expect(window.setTimeout.queue.length).toBe(0);
692+
}
693+
expect(element[0].style.display).toBe('');
694+
}));
695+
669696
it("should finish the previous transition when a new animation is started",
670697
inject(function($animator, $rootScope, $compile, $sniffer) {
671698
var style = 'transition: 1s linear all;' +

0 commit comments

Comments
 (0)