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

Commit 079dd93

Browse files
matskomhevery
authored andcommitted
fix($animate): ensure elapsedTime always considers delay values
1 parent 7ef9dbb commit 079dd93

File tree

2 files changed

+69
-61
lines changed

2 files changed

+69
-61
lines changed

src/ngAnimate/animate.js

+27-19
Original file line numberDiff line numberDiff line change
@@ -600,40 +600,43 @@ angular.module('ngAnimate', ['ng'])
600600
element.addClass(className);
601601

602602
//we want all the styles defined before and after
603-
var transitionTime = 0,
604-
animationTime = 0;
603+
var transitionDuration = 0,
604+
animationDuration = 0,
605+
transitionDelay = 0,
606+
animationDelay = 0;
605607
forEach(element, function(element) {
606608
if (element.nodeType == ELEMENT_NODE) {
607609
var elementStyles = $window.getComputedStyle(element) || {};
608610

609-
var transitionDelay = parseMaxTime(elementStyles[transitionProp + delayKey]);
611+
transitionDelay = Math.max(parseMaxTime(elementStyles[transitionProp + delayKey]), transitionDelay);
610612

611-
var animationDelay = parseMaxTime(elementStyles[animationProp + delayKey]);
613+
animationDelay = Math.max(parseMaxTime(elementStyles[animationProp + delayKey]), animationDelay);
612614

613-
var transitionDuration = parseMaxTime(elementStyles[transitionProp + durationKey]);
615+
transitionDuration = Math.max(parseMaxTime(elementStyles[transitionProp + durationKey]), transitionDuration);
614616

615-
var animationDuration = parseMaxTime(elementStyles[animationProp + durationKey]);
617+
var aDuration = parseMaxTime(elementStyles[animationProp + durationKey]);
616618

617-
if(animationDuration > 0) {
618-
animationDuration *= parseInt(elementStyles[animationProp + animationIterationCountKey]) || 1;
619+
if(aDuration > 0) {
620+
aDuration *= parseInt(elementStyles[animationProp + animationIterationCountKey]) || 1;
619621
}
620622

621-
transitionTime = Math.max(transitionDelay + transitionDuration, transitionTime);
622-
animationTime = Math.max(animationDelay + animationDuration, animationTime);
623+
animationDuration = Math.max(aDuration, animationDuration);
623624
}
624625
});
625626

626627
/* there is no point in performing a reflow if the animation
627628
timeout is empty (this would cause a flicker bug normally
628-
in the page */
629-
var maxTime = Math.max(transitionTime,animationTime) * 1000;
630-
if(maxTime > 0) {
631-
var node = element[0],
632-
startTime = Date.now();
629+
in the page. There is also no point in performing an animation
630+
that only has a delay and no duration */
631+
var maxDuration = Math.max(transitionDuration, animationDuration);
632+
if(maxDuration > 0) {
633+
var maxDelayTime = Math.max(transitionDelay, animationDelay) * 1000,
634+
startTime = Date.now(),
635+
node = element[0];
633636

634637
//temporarily disable the transition so that the enter styles
635638
//don't animate twice (this is here to avoid a bug in Chrome/FF).
636-
if(transitionTime > 0) {
639+
if(transitionDuration > 0) {
637640
node.style[transitionProp + propertyKey] = 'none';
638641
}
639642

@@ -644,7 +647,7 @@ angular.module('ngAnimate', ['ng'])
644647

645648
// This triggers a reflow which allows for the transition animation to kick in.
646649
element.prop('clientWidth');
647-
if(transitionTime > 0) {
650+
if(transitionDuration > 0) {
648651
node.style[transitionProp + propertyKey] = '';
649652
}
650653
element.addClass(activeClassName);
@@ -678,8 +681,13 @@ angular.module('ngAnimate', ['ng'])
678681
var ev = event.originalEvent || event;
679682
/* $manualTimeStamp is a mocked timeStamp value which is set
680683
* within browserTrigger(). This is only here so that tests can
681-
* mock animations properly. Real events fallback to event.timeStamp. */
682-
if((ev.$manualTimeStamp || ev.timeStamp) - startTime >= maxTime) {
684+
* mock animations properly. Real events fallback to event.timeStamp.
685+
* We're checking to see if the timestamp surpasses the expected delay,
686+
* but we're using elapsedTime instead of the timestamp on the 2nd
687+
* pre-condition since animations sometimes close off early */
688+
if((ev.$manualTimeStamp || ev.timeStamp) - startTime >= maxDelayTime &&
689+
ev.elapsedTime >= maxDuration) {
690+
683691
done();
684692
}
685693
}

0 commit comments

Comments
 (0)