1

How can i run again CSS animation every 5 minute?

html

<div></div>

css

div {
  width: 300px;
  height: 300px;
  animation: anim 1s;
  background: brown;
}
@keyframes anim {
  from {
    background: red;
  }
  top {
    background: blue;
  }
}

Need this without javascript

sall brown
  • 135
  • 2
  • 10

3 Answers3

2

You need to "fake" it if you want a pure CSS solution. Play with the percent property and the animation duration to simulate the delay.

For example

div {
  height: 20px;
  width: 20px;
  background-color: blue;
  animation: changebgc 5s infinite;
}
@keyframes changebgc {
  2% {
    background-color: red;
  }
  4% {
    background-color: blue;
  }
  98% {
    background-color: blue;
  }
}
<div></div>
Mehdi Brillaud
  • 1,846
  • 2
  • 13
  • 22
2

Doing this in CSS requires a bit of a hack, but it can be done. You are going to have to do a bit of math, and find how to correctly time the animation:

div {
  width: 300px;
  height: 300px;
  animation: anim 300s infinite;
  background: brown;
}

@keyframes anim {
  0% {
    background: red;
  }
  0.33% {
    background: blue;
  }
  100% {
    background: blue;
  }
}

JSFiddle demo
The one problem with this is that it is harder to change the timing. With the current setting, the red - blue transition takes 1 second, like you had in your JSFiddle.
How you calculate it is simple:
100 / #_seconds = percentage in animation for 1 sec e.g. 100 / 300 = 0.33

You can read more about this at this site:
http://samuelmichaud.fr/2013/web-design/add-a-delay-between-repeated-css3-animations/

Jacob G
  • 13,762
  • 3
  • 47
  • 67
0

I think you can play with the "animation-duration" and "animation-delay" rules. You can set a duration for the effect, and a delay just to wait until the next iteration.

div{
  width: 300px;
  height: 300px;

  background: brown;
  animation-name: anim;
  animation-duration: 10s;
  animation-iteration-count: 10000;
  animation-direction: alternate;
  animation-timing-function: ease-out;
  animation-fill-mode: forwards;
  animation-delay: 50s;
}
@keyframes anim {
  from {
    background: red;
  }
  to {
    background: blue;
  }
}

Hope it helps.

Regards

Estefano
  • 26
  • 1