Skip to content

Commit e90aa97

Browse files
committed
Do not animate 'display' or animation/transition properties.
Certain properties are not animatable. For example, properties defining animation parameters are not animatable. https://w3c.github.io/web-animations/#concept-not-animatable Web Animations must ignore such properties. This closes #394
1 parent 853d61c commit e90aa97

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/normalize-keyframes.js

+8
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,16 @@
150150
return value;
151151
}
152152

153+
function isNotAnimatable(property) {
154+
// https://w3c.github.io/web-animations/#concept-not-animatable
155+
return property === 'display' || property.lastIndexOf('animation', 0) === 0 || property.lastIndexOf('transition', 0) === 0;
156+
}
157+
153158
// This delegates parsing shorthand value syntax to the browser.
154159
function expandShorthandAndAntiAlias(property, value, result) {
160+
if (isNotAnimatable(property)) {
161+
return;
162+
}
155163
var longProperties = shorthandToLonghand[property];
156164
if (longProperties) {
157165
shorthandExpanderElem.style[property] = value;

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('Not Animatable properties are not animated', function() {
359+
var target = document.createElement('div');
360+
target.style.opacity = 0;
361+
target.style.display = 'block';
362+
target.style['animation-timing-function'] = 'ease-in';
363+
target.style['transition-duration'] = '2s';
364+
document.body.appendChild(target);
365+
366+
var keyframeEffect = new KeyframeEffect(target, [
367+
{opacity: '0.75', display: 'none', animationTimingFunction: 'linear', transitionDuration: '5s'},
368+
{opacity: '0.25', display: 'none', animationTimingFunction: 'linear', transitionDuration: '5s'}
369+
], 2000);
370+
371+
var animation = document.timeline.play(keyframeEffect);
372+
373+
tick(0);
374+
assert.equal(getComputedStyle(target).opacity, 0.75);
375+
376+
tick(1000);
377+
assert.equal(getComputedStyle(target).opacity, 0.5);
378+
assert.equal(getComputedStyle(target).display, 'block');
379+
assert.equal(getComputedStyle(target).animationTimingFunction, 'ease-in');
380+
assert.equal(getComputedStyle(target).transitionDuration, '2s');
381+
});
357382
});

0 commit comments

Comments
 (0)