Skip to content

Commit c704991

Browse files
committed
Do not animate 'display' or the 'animation*' properties.
1 parent 853d61c commit c704991

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/normalize-keyframes.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@
150150
return value;
151151
}
152152

153+
function isPermittedKeyframeProperty(property) {
154+
return property !== 'display' && property.lastIndexOf('animation', 0) === -1;
155+
}
156+
153157
// This delegates parsing shorthand value syntax to the browser.
154158
function expandShorthandAndAntiAlias(property, value, result) {
155159
var longProperties = shorthandToLonghand[property];
@@ -160,7 +164,7 @@
160164
var longhandValue = shorthandExpanderElem.style[longProperty];
161165
result[longProperty] = antiAlias(longProperty, longhandValue);
162166
}
163-
} else {
167+
} else if (isPermittedKeyframeProperty(property)) {
164168
result[property] = antiAlias(property, value);
165169
}
166170
};

test/js/keyframe-effect-constructor.js

+25
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,29 @@ suite('keyframe-effect-constructor', function() {
354354
effect.timing.iterations = 2;
355355
assert.closeTo(Number(getComputedStyle(target).opacity), 0.75, 0.01, 't=125 after setting iterations');
356356
});
357+
358+
test('display and animation* properties are not animated', function() {
359+
var target = document.createElement('div');
360+
target.style.position = 'absolute';
361+
target.style.display = 'block';
362+
target.style['animation-timing-function'] = 'ease-in';
363+
document.body.appendChild(target);
364+
365+
var keyframeEffect = new KeyframeEffect(target, [
366+
{opacity: '0.75', display: 'none', animationTimingFunction: 'linear'},
367+
{opacity: '0.25', display: 'none', animationTimingFunction: 'linear'}
368+
], 2000);
369+
370+
var animation = document.timeline.play(keyframeEffect);
371+
372+
tick(0);
373+
assert.equal(getComputedStyle(target).opacity, 0.75);
374+
assert.equal(getComputedStyle(target).display, 'block');
375+
assert.equal(getComputedStyle(target).animationTimingFunction, 'ease-in');
376+
377+
tick(1000);
378+
assert.equal(getComputedStyle(target).opacity, 0.5);
379+
assert.equal(getComputedStyle(target).display, 'block');
380+
assert.equal(getComputedStyle(target).animationTimingFunction, 'ease-in');
381+
});
357382
});

0 commit comments

Comments
 (0)