animating border to transparent with keyframes - html

I'm trying to make simple animation of a circle which border goes from red to transparent color. How I'm trying to do it is to set initial color as red and then animate it to transparent with keyframes like so:
.pulse{
margin: 20px;
width:100px;
height: 100px;
background-color: red;
border-radius: 100px;
animation-name: pulse;
animation-duration: 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-timing-function: ease;
}
#keyframes pulse{
0%{border:solid 1px rgba(255, 0, 0, 1)}
100%{border:solid 1px rgba(255, 0, 0, 0)}
}
<div class="animation">
<div class="pulse"></div>
</div>
Seemingly nothing happens but after fiddling with it a bit I'm aware that the animation actually works, but the transparent animation is shown on top of existing red border and effect is that it looks like nothing is happening.
What i'm trying to achive is to have the border go from red to transparent, making it look like it's pulsating but without the circle changing it's size.

Try box-shadow instead of border
Stack Snippet
.pulse {
margin: 20px;
width: 100px;
height: 100px;
background-color: red;
border-radius: 100px;
animation-name: pulse;
animation-duration: 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-timing-function: linear;
}
#keyframes pulse {
0% {
box-shadow: 0 0 0 4px rgba(255, 0, 0, 1);
}
100% {
box-shadow: 0 0 0 0px rgba(255, 0, 0, 1);
}
}
<div class="animation">
<div class="pulse"></div>
</div>

You won't see anything because you background-color is the same color as the border color. Also your border definition inside your animation was wrong, the width must come before the border style:
So for example it's 1px solid color instead of solid 1px rgba(255,0,0,1).
.pulse {
animation: pulse 1s ease infinite alternate;
background-color: #ddd;
border-radius: 100px;
height: 100px;
margin: 20px;
width: 100px;
}
#keyframes pulse {
0% {
border: 1px solid rgba(255, 0, 0, 1)
}
100% {
border: 1px solid rgba(255, 0, 0, 0)
}
}
<div class="animation">
<div class="pulse"></div>
</div>
But i think you want to achieve a pulsating effect, therefore i would recommend you to use transform: scale() to create the desired effect.
#keyframes pulse{
from { transform: scale(1) }
to { transform: scale(.75) }
}
.pulse{
margin: 20px;
width:100px;
height: 100px;
border-radius: 100px;
background-color: red;
animation: pulse 1s ease infinite alternate;
}
<div class="animation">
<div class="pulse"></div>
</div>

Just add background-clip: padding-box; to the .pulse element. More info here. As said in the previous answer, you can also use the box-shadow, but you have to keep in mind that box shadow does not take space around the element. So You will have a different behavior.
.pulse {
background-clip: padding-box;
margin: 20px;
width:100px;
height: 100px;
background-color: red;
border-radius: 100px;
animation-name: pulse;
animation-duration: 1s;
animation-iteration-count: infinite;
animation-timing-function: ease;
}
#keyframes pulse{
0%{border:solid 1px rgba(255, 0, 0, 1)}
100%{border:solid 1px rgba(255, 0, 0, 0)}
}
<div class="animation">
<div class="pulse"></div>
</div>

Related

How to change the button colour after playing animation in css

I am trying to change colour of button after playing animation for some time. What I have searched and found that, it needs to change a new frame. Here is my CSS:
.header-button {
font-size: 12px;
text-shadow: 0 -1px 0 rgba(0, 0, 0, .8);
color: #fbd3cc;
text-decoration: none;
font-weight: normal;
height: 30px;
border: 1px solid rgba(255, 255, 255, .4);
border-radius: 3px;
-webkit-border-radius: 3px;
display: inline;
background: #026890;
}
#keyframes fadeIn {
from {
opacity: 0;
}
}
.animate-flicker {
animation: fadeIn 0.5s infinite alternate;
animation-iteration-count: 10;
-moz-animation-name: changecolor;
}
#keyframes changecolor {
{
color: red;
}
}
<button class="header-button animate-flicker">Menue
</button>
Can some one tell me how i can change the button colour after playing animation for 5 times in css
You need to make both animations either:
In the same keyframes
#keyframes fadeInNColor {
from {
opacity: 0;
}
to {
color: red;
}
}
or call each of them from the same rule
animation: fadeIn 0.5s infinite alternate, changecolor 0.5s infinite alternate forwards;
.header-button {
font-size: 12px;
text-shadow: 0 -1px 0 rgba(0, 0, 0, .8);
color: #fbd3cc;
text-decoration: none;
font-weight: normal;
height: 30px;
border: 1px solid rgba(255, 255, 255, .4);
border-radius: 3px;
-webkit-border-radius: 3px;
display: inline-block;
background: #026890;
}
#keyframes fadeIn {
from {
opacity: 0;
}
}
.animate-flicker {
animation:
fadeIn 0.5s infinite alternate, /* first animation*/
changecolor 0.5s infinite alternate forwards;/* second animation freezed */
animation-iteration-count: 5;
}
#keyframes changecolor {
to {
color: red;
}
}
<button class="header-button animate-flicker">Menue
</button>
you can add a span into the button tag and apply the color change to the span by delaying it by a few seconds to finish the nimation
Hope this is what you are looking for:
#keyframes changecolor
{
to {background:red;}
}

How to rotate the border colors of a div

Fiddle: https://jsfiddle.net/t11738dm/
HTML:
<div class="ball-5"></div>
How can I rotate 360 degree, only the border colors of the div?
I tried the following but that rotates the entire div which I don't want:
.ball-5 {
-webkit-animation-name: Rotate;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: Rotate;
-moz-animation-duration: 2s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: Rotate;
-ms-animation-duration: 2s;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
}
#-webkit-keyframes Rotate {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
#-moz-keyframes Rotate {
from {
-moz-transform: rotate(0deg);
}
to {
-moz-transform: rotate(360deg);
}
}
#-ms-keyframes Rotate {
from {
-ms-transform: rotate(0deg);
}
to {
-ms-transform: rotate(360deg);
}
}
I would like to have the colors race around the div not the div nor the content of the div to go in circle.
The only solution I can think of is using pseudo elements (or nested elements) to decouple the border and the center.
.ball-5 {
background: #fff;
border-radius: 500px;
box-shadow: 0px 0px 10px #222;
padding: 10px;
cursor: pointer;
overflow:hidden;
border:0px;
}
.ball-5 {
position:relative;
width: 115px;
height: 70px;
}
.ball-5:before{
display:block;position:absolute;
top:-55px;left:-30px;
content:"";width:0px;height:0px;
border: solid 100px;
border-top-color: rgba(156, 206, 228, 1);
border-right-color: rgba(122, 183, 142, 1);
border-bottom-color: rgba(255, 177, 38, 1);
border-left-color: rgba(241, 139, 41, 1);
}
.ball-5:after{
display:block;position:absolute;
top:10px;left:10px;
content:"";
width: 115px;
height: 70px;
background:white;
border-radius: 500px;
}
.ball-5:before {
animation: Rotate 2s infinite linear;
}
#keyframes Rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
<div class="ball-5">
</div>
I would say having a div over it that has a transparent background and is the div that has the borders. Then that div rotates on top and it looks like it is the border of the actual element rotating.
Try this:
#containerDiv {
position: relative;
}
#div, #div2 {
position: absolute;
left: 0px; top: 0px;
}
#div2 {
z-index: 5;
background: transparent;
border: 1px black solid;
}
#div {
background: #f00;
}
div2 will be the animated one and div will be the non-border one. The container will have div and div2 inside it.

HTML5 Animation working on Chrome but not Firefox

The following is an earth globe that's rotating. Though this animation is working fine on Chrome, it doesn't work at all on Firefox, and it just stands still. Any help on how to solve this?
JSFiddle.
<div id="page-wrapper">
<div class="row">
<div class="center-block img-responsive" id="earth"></div>
</div>
</div>
#earth {
width: 100px;
height: 100px;
background: url('../images/Earth-Color.jpg');
border-radius: 50%;
background-size: 210px;
box-shadow: inset 16px 0 40px 6px rgb(0, 0, 0),
inset -3px 0 6px 2px rgba(255, 255, 255, 0.2);
animation-name: rotate;
animation-duration: 4s;
animation-iteration-count: infinite;
animation-timing-function: linear;
margin-top:200px;
}
#keyframes rotate {
from { background-position-x: 0px; }
to { background-position-x: 210px; }
}
You need to set the background-position property as a whole in #keyframes
#keyframes rotate {
from { background-position: 0px 0; }
to { background-position: 210px 0; }
}
jsFiddle
background-position-x and background-position-y are not yet implemented in FireFox. But it seems like they will be added in future.
Another SO question on this

How to animate the progress element with CSS3?

I have a progress element like so:
body {
background: grey;
}
progress[value] {
-webkit-appearance: none;
appearance: none;
height: 25px;
width: 95%;
position: relative;
top: 10px;
right: 50%;
left: 2.5%;
}
progress[value]::-webkit-progress-bar {
background-color: rgba(255,255,255,0.2);
border-radius: 50px;
border: solid;
border-width: 0px;
border-color: rgba(255,255,255,0.1);
}
progress[value]::-webkit-progress-value {
background-image: repeating-linear-gradient(
45deg,
#fff,
#fff 10px,
#f9f9f9 10px,
#f9f9f9 20px
);
border-radius: 50px;
-moz-animation-name: move;
-moz-animation-iteration-count: 1;
-moz-animation-timing-function: ease;
-moz-animation-duration: 0.4s;
-moz-animation-delay: 1.5s;
-moz-animation-fill-mode: forwards;
-webkit-animation-name: move;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: linear;
-webkit-animation-duration: 0.4s;
animation-delay: 1.5s;
animation-name: move;
animation-iteration-count: infinite;
animation-timing-function: linear;
animation-delay: 1.5s;
animation-play-state: running;
}
#keyframes move {
0% {
background-position: 0 0;
}
100% {
background-position: 50px 50px;
}
}
<progress max="100" value="80"></progress>
And I have used CSS animations, however for some reason they do not work. I want the stripes to move horizontally, infinitely. Is there any reason to why this doesn't work?
Note - <progress> is not well supported by IE. See this for a complete guide to make it work across browsers. Below demo is the simplified animation without <progress> element.
body {
background-color: #666;
}
div {
background-color: #999;
border-radius: 30px;
height: 30px;
}
div > div {
background-image: repeating-linear-gradient(-45deg, #fff, #fff 10px, #ccc 10px, #ccc 20px);
background-size: 28px 30px;
animation: progress 2s linear infinite;
width: 50%;
}
#keyframes progress {
0% { background-position: 0 0; }
100% { background-position: 28px 0; }
}
<div><div></div></div>

I have two div elements that I want both to CSS pulsate when hovering either

I have two div elements that I want both to puslate (CSS animation) if mouse hovers on any one of them. There a simple code following. In my page they are not next each other. The above code does not works.
jsfiddle: http://jsfiddle.net/GcyqL/1/
CSS:
#counter {
width:120px;
height:25px;
text-align: center;
border-style: solid;
border-width: 1px;
background-color: rgb(142, 197, 255);
font-weight: bold;
}
#mem_val {
width:120px;
height:25px;
text-align: center;
border-style: solid;
border-width: 1px;
background-color: rgb(142, 197, 255);
font-weight: bold;
}
div.intro:hover{
-webkit-animation: pulsate 1s infinite alternate;
-moz-animation: pulsate 1s infinite alternate;
-animation: pulsate 1s infinite alternate;
text-shadow: 0 0 8px #ccc;
}
#-webkit-keyframes pulsate {
from { box-shadow: 0 0 10px #333; }
to { box-shadow: 0 0 20px #c00; }
}
#-moz-keyframes pulsate {
from { box-shadow: 0 0 10px #333; }
to { box-shadow: 0 0 20px #c00; }
}
#keyframes pulsate {
from { box-shadow: 0 0 10px #333; }
to { box-shadow: 0 0 20px #c00; }
}
HTML
<div id="mem_val" class="intro" >mem_val</div><br><br>
<div id="counter" class="intro">counter</div><br><br>
If you want to do it only with CSS, you can add them both to the same container and use the container's hover selector.
Notice that this solution will make the hover animation even if the container is being hovered outside of these two elements. You can walk around this issue with a little trick that'll make the container stay "invisible", although it might be a bit non-flexible.
jsFiddle Demo
#container {
width:0;
height:0;
overflow: visible;
}
/* Old selector: div.intro:hover */
#container:hover div.intro {
-webkit-animation: pulsate 1s infinite alternate;
-moz-animation: pulsate 1s infinite alternate;
-animation: pulsate 1s infinite alternate;
text-shadow: 0 0 8px #ccc;
}
Add jQuery and here's a solution, DEMO
$(document).ready(function(){
$('.pulsate').hover(
function(){
$('.pulsate').addClass('intro');
},
function(){
$('.pulsate').removeClass('intro');
}
);
});
Just put them inside a container with display:inline; and then use
#container:hover div {
//plusate...
}
Demo: http://jsfiddle.net/GcyqL/8/
Pure css.