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?
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 .
You can add the . blink class to any HTML element to make it blink.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With