Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blinking background color animation

Tags:

I'm trying to create sort of blinking element animation. It should last one second - half second it has red border and green BG, and another half second green border and red BG. The change of colors should be just about immediate.

I tried it like this:

0, 49%, 99%, 100% {
    background-color: rgb(117,209,63);
    border: 3px solid #e50000;
}
49%, 50%, 99% {
    background-color: #e50000;
    border: 3px solid rgb(117,209,63);
}

It sort of worked, but the color transition was very slow. I tried also this:

0%, 49% {
    background-color: rgb(117,209,63);
    border: 3px solid #e50000;
}
49%, 50% {
    background-color: #e50000;
    border: 3px solid rgb(117,209,63);
}
50%, 99% {
    background-color: #e50000;
    border: 3px solid rgb(117,209,63);
}
99%, 100% {
    background-color: rgb(117,209,63);
    border: 3px solid #e50000;
}

and this:

0%, 50% {
    background-color: rgb(117,209,63);
    border: 3px solid #e50000;
}
50%, 99% {
    background-color: #e50000;
    border: 3px solid rgb(117,209,63);
}

But nothing worked as expected... Any help, please?

like image 497
Igal Avatar asked Dec 23 '15 16:12

Igal


People also ask

What does blinking background effect do?

This essentially makes the color change from 0 - 50% (slow). Instead, all you needed to do was make the keyframes as 0%, 50% and 50.1%, 99% (or give a 1% split like in Marcel's snippet). The other thing to note, is the frames should always be % . Even 0 should be represented as 0% or from and not 0 .

How do you make a flashing background in HTML?

You can add the . blink class to any HTML element to make it blink.


1 Answers

Take a look at this. This fiddle should be pretty accurate:

.quadrat {
  width: 50px;
  height: 50px;
  -webkit-animation: NAME-YOUR-ANIMATION 1s infinite;  /* Safari 4+ */
  -moz-animation: NAME-YOUR-ANIMATION 1s infinite;  /* Fx 5+ */
  -o-animation: NAME-YOUR-ANIMATION 1s infinite;  /* Opera 12+ */
  animation: NAME-YOUR-ANIMATION 1s infinite;  /* IE 10+, Fx 29+ */
}

@-webkit-keyframes NAME-YOUR-ANIMATION {
  0%, 49% {
    background-color: rgb(117, 209, 63);
    border: 3px solid #e50000;
  }
  50%, 100% {
    background-color: #e50000;
    border: 3px solid rgb(117, 209, 63);
  }
}
<div class="quadrat"></div>
like image 112
Marcel Wasilewski Avatar answered Oct 06 '22 04:10

Marcel Wasilewski