Search code examples
cssanimationwebkit

Webkit memory limit with -webkit-animation


I'm faced with a memory issue, using -webkit-animation.

Principle

I want to animate a gradient background. As they are not animatable in keyframes, I put each background in a different div, and I'm playing with those div opacity and z-index :

  • .item01 is visible from 0% to 4%, starting to fade out at 0%
  • .item02 is visible from 0% to 8%, starting to fade out at 4% (and under .item01)
  • .item03 is visible from 0% to 12%, starting to fade out at 8% (and under .item02)
  • ...

Problem

Only the 16 first animations work, on the 17th we just see a blank div, until the restart of all animations.

I noticed I don't have the problem using -moz-animation and Firefox, the issue only happens on Chrome, using -webkit-.

Depending of your viewport size, you'll be able to see more or less animations.

Code

HTML

<div class="item item-01">ITEM 01</div>
<div class="item item-02">ITEM 02</div>
<div class="item item-03">ITEM 03</div>
...

CSS

.item {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  opacity: 1;
}
.item-01 { 
  background: red; 
  z-index: 100; 
  -webkit-animation: item01 30s linear infinite;
}
.item-02 { 
  background: blue; 
  z-index: 96; 
  -webkit-animation: item02 30s linear infinite;
}
.item-03 { 
  background: red; 
  z-index: 92; 
  -webkit-animation: item03 30s linear infinite;
}
...
@-webkit-keyframes item01 { 0%, 100% {opacity: 1;}  4%, 99.999% {opacity: 0;} }
@-webkit-keyframes item02 { 4%, 100% {opacity: 1;}  8%, 99.999% {opacity: 0;} }
@-webkit-keyframes item03 { 8%, 100% {opacity: 1;} 12%, 99.999% {opacity: 0;} }
...

For the example purpose, I replaced gradient backgrounds by simple red/blue ones.

Any way to make this code work ?

EDIT
I updated my question, following to my recent found :

  • Number of animations shown depends of your OS (Ubuntu seems to have better results than Win7)
  • Number of animations shown depends of your viewport size

Solution

  • This was indeed a webkit bug, that no longer exists for years.