How to bound CSS3 animation to class - css

I'm new to css so possible asking question in wrong way.
I have a simple pulsating animation. In CSS file is this code:
.pulsor_red {
-webkit-animation: pulsate .4s infinite linear;
-moz-animation: pulsate .4s infinite alternate;
-animation: pulsate .4s infinite alternate;
}
#-webkit-keyframes pulsate {
from { box-shadow: 0 0 8px red; }
to { box-shadow: 0 0 20px red; }
}
#-moz-keyframes pulsate {
from { box-shadow: 0 0 10px red; }
to { box-shadow: 0 0 20px red; }
}
#keyframes pulsate {
from { box-shadow: 0 0 10px red; }
to { box-shadow: 0 0 20px red; }
}
.pulsor_orange {
-webkit-animation: pulsate .4s infinite alternate;
-moz-animation: pulsate .4s infinite alternate;
-animation: pulsate .4s infinite alternate;
}
#-webkit-keyframes pulsate {
from { box-shadow: 0 0 8px #ffac00; }
to { box-shadow: 0 0 20px #ffac00; }
}
#-moz-keyframes pulsate {
from { box-shadow: 0 0 10px #ffac00; }
to { box-shadow: 0 0 20px #ffac00; }
}
#keyframes pulsate {
from { box-shadow: 0 0 10px #ffac00; }
to { box-shadow: 0 0 20px #ffac00; }
}
I would like to set class on one div pulsor_red and to other one pulsor_orange for one pulsating red and other orange (#ffac00).
How to do it?
click for jsfiddle

Just use unique names for both animations (notice the first and second):
div{
width:150px;
height:150px;
}
.pulsor_red {
-webkit-animation: first .4s infinite alternate;
-moz-animation: first .4s infinite alternate;
-animation: first .4s infinite alternate;
}
#-webkit-keyframes first {
from { box-shadow: 0 0 8px red; }
to { box-shadow: 0 0 20px red; }
}
#-moz-keyframes first {
from { box-shadow: 0 0 10px red; }
to { box-shadow: 0 0 20px red; }
}
#keyframes first {
from { box-shadow: 0 0 10px red; }
to { box-shadow: 0 0 20px red; }
}
.pulsor_orange {
-webkit-animation: second .4s infinite alternate;
-moz-animation: second .4s infinite alternate;
-animation: second .4s infinite alternate;
}
#-webkit-keyframes second {
from { box-shadow: 0 0 8px #ffac00; }
to { box-shadow: 0 0 20px #ffac00; }
}
#-moz-keyframes second {
from { box-shadow: 0 0 10px #ffac00; }
to { box-shadow: 0 0 20px #ffac00; }
}
#keyframes second {
from { box-shadow: 0 0 10px #ffac00; }
to { box-shadow: 0 0 20px #ffac00; }
}
<div class="pulsor_red">xxxxxx</div>
<div class="pulsor_orange">yyyyyy</div>

Related

2 css animation call for 1 element

Why does the animation only work when element appear but not when you hover?
body {
text-align: center;
padding-top: 50px;
font-family: sans-serif;
}
span {
background: dodgerblue;
border-radius: 4px;
padding: 10px 20px;
animation-name: pulse;
animation-duration: 2s;
animation-iteration-count: 4;
animation-delay: 3s;
}
span:hover {
animation-name: pulse;
animation-duration: 2s;
animation-iteration-count: 1;
animation-delay: .2s;
}
#keyframes pulse {
0% {
box-shadow: 0 0 0 0px dodgerblue
}
50% {
box-shadow: 0 0 0 20px transparent
}
100% {
box-shadow: 0 0 0 0px transparent
}
}
<span>
Test
</span>
https://codepen.io/umasterov/pen/XWJGLQV
if you remove the animation when it appears, the hover animation works
You have several options:
Duplicating the animation
body {
text-align: center;
padding-top: 50px;
font-family: sans-serif;
}
span {
background: dodgerblue;
border-radius: 4px;
padding: 10px 20px;
animation-name: pulse;
animation-duration: 2s;
animation-iteration-count: 4;
animation-delay: 3s;
}
span:hover {
animation-name: pulse2;
animation-duration: 2s;
animation-iteration-count: 1;
animation-delay: .2s;
}
#keyframes pulse {
0% {
box-shadow: 0 0 0 0px dodgerblue
}
50% {
box-shadow: 0 0 0 20px transparent
}
100% {
box-shadow: 0 0 0 0px transparent
}
}
#keyframes pulse2 {
0% {
box-shadow: 0 0 0 0px dodgerblue
}
50% {
box-shadow: 0 0 0 20px transparent
}
100% {
box-shadow: 0 0 0 0px transparent
}
}
<span>
Test
</span>
Using pseudo-element
body {
text-align: center;
padding-top: 50px;
font-family: sans-serif;
}
span {
position: relative;
display: inline-block;
background: dodgerblue;
border-radius: 4px;
padding: 10px 20px;
animation-name: pulse;
animation-duration: 2s;
animation-iteration-count: 4;
animation-delay: 3s;
}
span:hover::before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
border-radius: 4px;
animation-name: pulse;
animation-duration: 2s;
animation-iteration-count: 1;
animation-delay: .2s;
}
#keyframes pulse {
0% {
box-shadow: 0 0 0 0 dodgerblue
}
50% {
box-shadow: 0 0 0 20px transparent
}
100% {
box-shadow: 0 0 0 0 transparent
}
}
<span>
Test
</span>
You just need to take your animation off the normal state
body {
text-align: center;
padding-top: 50px;
font-family: sans-serif;
}
span {
background: dodgerblue;
border-radius: 4px;
padding: 10px 20px;
}
span:hover {
animation-name: pulse;
animation-duration: 2s;
animation-iteration-count: 1;
animation-delay: .2s;
}
#keyframes pulse {
0% {box-shadow: 0 0 0 0px dodgerblue}
50% {box-shadow: 0 0 0 20px transparent}
100% {box-shadow: 0 0 0 0px transparent}
}

Gradient animation remains color in cycle after a hover

curious how I can get the color of my h1 text to stay on the current color in cycle after hovering and activating the rainbow animation!
h1 {
margin: 0;
font-size: 5em;
color: #00f;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}
h1:hover{
-webkit-animation: rainbow 10s infinite;
}
#-webkit-keyframes rainbow{
20%{color: red; left 600ms 3s, top 1.5s 3s;}
40%{color: yellow; left 600ms 3s, top 1.5s 3s;}
60%{color: green; left 600ms 3s, top 1.5s 3s;}
80%{color: orange; left 600ms 3s, top 1.5s 3s;}
100%{color: blue; left 600ms 3s, top 1.5s 3s;}
You can rely on the animation-play-state property like this:
h1 {
margin: 0;
font-size: 5em;
color: #00f;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
animation: rainbow 10s infinite;
animation-play-state: paused;
}
h1:hover {
animation-play-state: running;
}
#keyframes rainbow {
20% {
color: red;
}
40% {
color: yellow;
}
60% {
color: green;
}
80% {
color: orange;
}
100% {
color: blue;
}
<h1>SOME TEXT</h1>

How to add two animation styles to an element

I am working on this CSS snippet. Why am I not able to add both pulse and fadeout animation roles to the span?
Technically I like to have both in one animation or enable to accept both pulse and fadeout animation
html,body {
height:100%;
width:100%;
}
#point {
height:100%;
width:100%;
position:relative;
}
.pulse {
position:absolute;
margin:30px;
display: block;
width: 22px;
height: 22px;
border-radius: 50%;
background: #cca92c;
cursor: pointer;
box-shadow: 0 0 0 rgba(204,169,44, 0.4);
animation: pulse 2s infinite;
}
.pulse:hover {
animation: none;
}
#-webkit-keyframes pulse {
0% {
-webkit-box-shadow: 0 0 0 0 rgba(204,169,44, 0.4);
}
70% {
-webkit-box-shadow: 0 0 0 10px rgba(204,169,44, 0);
}
100% {
-webkit-box-shadow: 0 0 0 0 rgba(204,169,44, 0);
}
}
#keyframes pulse {
0% {
-moz-box-shadow: 0 0 0 0 rgba(204,169,44, 0.4);
box-shadow: 0 0 0 0 rgba(204,169,44, 0.4);
}
70% {
-moz-box-shadow: 0 0 0 10px rgba(204,169,44, 0);
box-shadow: 0 0 0 10px rgba(204,169,44, 0);
}
100% {
-moz-box-shadow: 0 0 0 0 rgba(204,169,44, 0);
box-shadow: 0 0 0 0 rgba(204,169,44, 0);
}
}
.hideMe {
-webkit-animation: seconds 1.0s forwards;
-webkit-animation-iteration-count: 1;
-webkit-animation-delay: 5s;
animation: seconds 1.0s forwards;
animation-iteration-count: 1;
animation-delay: 5s;
}
#-webkit-keyframes seconds {
0% {
opacity: 1;
}
100% {
opacity: 0;
left: -9999px;
}
}
#keyframes seconds {
0% {
opacity: 1;
}
100% {
opacity: 0;
left: -9999px;
}
}
<span class="pulse hideMe"></span>
.dot {
position: absolute;
margin: 30px;
display: block;
width: 22px;
height: 22px;
border-radius: 50%;
background: #cca92c;
cursor: pointer;
box-shadow: 0 0 0 rgba(204, 169, 44, 0.4);
opacity: 1;
}
.dot--animation {
animation: pulse 2s infinite,
hide .3s forwards 5s;
}
.dot--animation:hover {
animation: none;
}
#keyframes pulse {
0% {
-moz-box-shadow: 0 0 0 0 rgba(204, 169, 44, 0.4);
box-shadow: 0 0 0 0 rgba(204, 169, 44, 0.4);
}
70% {
-moz-box-shadow: 0 0 0 10px rgba(204, 169, 44, 0);
box-shadow: 0 0 0 10px rgba(204, 169, 44, 0);
}
100% {
-moz-box-shadow: 0 0 0 0 rgba(204, 169, 44, 0);
box-shadow: 0 0 0 0 rgba(204, 169, 44, 0);
}
}
#keyframes hide {
100% {
opacity: 0;
}
}
<div class="dot dot--animation"></div>
You are overwriting your .pulse animation with the .second animation. You need to either include both animations in the same keyframe set or seperate the keyframe sets by comma on the animate property. Alternatively you could use a wrapper, put the fadeout on the wrapper and the pulse on the actual span.
Css properties do not 'stack' on each other, they are replaced by later instances, that is true also for animate.

CSS3 Tranisition Box Shadow Pulse

I'm trying to ensure that only the box shadow has the pulsate and not the whole button.
The experience should see the button solid but with the box shadow fading in and out if that makes sense.
Here is my code:
.gps_ring {
border: 3px solid #999;
-webkit-border-radius: 30px;
height: 42px;
width: 180px;
background-color: blue;
text-align: center;
display: block;
color: white;
box-shadow: 0 0 17px black;
-moz-box-shadow: 0 0 17px black;
-webkit-box-shadow: 0 0 17px black;
-webkit-animation: pulsate 1s ease-out;
-webkit-animation-iteration-count: infinite;
opacity: 0.0
}
#-webkit-keyframes pulsate {
0% {-webkit-transform: scale(0.1, 0.1); opacity: 0.0;}
50% {opacity: 1.0;}
100% {-webkit-transform: scale(1.2, 1.2); opacity: 0.0;}
}
EXAMPLE
Simply animate only the shadow, like this
.gps_ring {
border: 3px solid #999;
border-radius: 30px;
height: 42px;
width: 180px;
background-color: blue;
text-align: center;
display: block;
color: white;
box-shadow: 0 0 17px black;
animation: pulsate 1s ease-out infinite;
}
#-webkit-keyframes pulsate {
0% { box-shadow: 0 0 0 black; }
50% { box-shadow: 0 0 17px black; }
100% { box-shadow: 0 0 0 black; }
}
<div id="state" class="grid_4 alpha">
Touch me
</div>
I think this is what you need. Better solution http://codepen.io/governorfancypants/pen/zvMxWm
<div class="circle">
<div class="inner-circle"></div>
<div class="cover-circle"></div>
</div>
.pulsating-circle {
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
width: 30px;
height: 30px;
&:before {
content: '';
position: relative;
display: block;
width: 300%;
height: 300%;
box-sizing: border-box;
margin-left: -100%;
margin-top: -100%;
border-radius: 45px;
background-color: #01a4e9;
animation: pulse-ring 1.25s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}
&:after {
content: '';
position: absolute;
left: 0;
top: 0;
display: block;
width: 100%;
height: 100%;
background-color: white;
border-radius: 15px;
box-shadow: 0 0 8px rgba(0,0,0,.3);
animation: pulse-dot 1.25s cubic-bezier(0.455, 0.03, 0.515, 0.955) -.4s infinite;
}
}
#keyframes pulse-ring {
0% {
transform: scale(.33);
}
80%, 100% {
opacity: 0;
}
}
#keyframes pulse-dot {
0% {
transform: scale(.8);
}
50% {
transform: scale(1);
}
100% {
transform: scale(.8);
}
}
HTML
<span class="pulse"></span>
CSS
.pulse {
margin:80px;
display: block;
width: 100px;
height: 100px;
border-radius: 50%;
background: #cca92c;
cursor: pointer;
box-shadow: 0 0 0 rgba(0,0,0, 0.4);
animation: none;
}
.pulse:hover {
animation: pulse 2s infinite;
}
#-webkit-keyframes pulse {
0% {
-webkit-box-shadow: 0 0 0 0 rgba(0,0,0, 0.5);
}
70% {
-webkit-box-shadow: 0 0 0 50px rgba(0,0,0, 0);
}
100% {
-webkit-box-shadow: 0 0 0 0 rgba(0,0,0, 0);
}
}
#keyframes pulse {
0% {
-moz-box-shadow: 0 0 0 0 rgba(0,0,0, 0.5);
box-shadow: 0 0 0 0 rgba(0,0,0, 0.4);
}
70% {
-moz-box-shadow: 0 0 0 50px rgba(0,0,0, 0);
box-shadow: 0 0 0 50px rgba(0,0,0, 0);
}
100% {
-moz-box-shadow: 0 0 0 0 rgba(0,0,0, 0);
box-shadow: 0 0 0 0 rgba(0,0,0, 0);
}
}
Hover effect.
CodePen: https://codepen.io/smith-harshan/pen/MWpGXeY
Hope this would be a help.

CSS keyframe animate border issue

I'm trying to animate smoothly some css triangles, I have this:
but nothing happen's - can anyone point me in the right direction please.
Thanks:
.angle-1 {
position: absolute; bottom: 0;
width: 0; height: 0;
border-style: solid;
border-width: 200px 0 0 1440px;
border-color: transparent transparent transparent #007bff;
opacity: 0.7;
-webkit-animation: moveangle1 2s infinite;
-moz-animation: moveangle1 2s infinite;
-o-animation: moveangle1 2s infinite;
animation: moveangle1 2s infinite;
}
#keyframes moveangle1,
#-o-keyframes moveangle1,
#-moz-keyframes moveangle1,
#-webkit-keyframes moveangle1 {
0% { border-width: 200px 0 0 1440px; opacity: 0.7; }
100% { border-width: 400px 0 0 1000px; opacity: 0.4; }
}
Here is an example: https://jsfiddle.net/sp2emgtc/
You cannot combine vendor prefixed keyframe statements into a single rule.
They must be stated separately.
.angle-1 {
width: 0;
height: 0;
border-style: solid;
border-width: 200px 0 0 1440px;
border-color: transparent transparent transparent #007bff;
opacity: 0.7;
-webkit-animation: moveangle1 2s infinite;
animation: moveangle1 2s infinite;
}
#-webkit-keyframes moveangle1 {
0% {
border-width: 200px 0 0 1440px;
opacity: 0.7;
}
100% {
border-width: 400px 0 0 1000px;
opacity: 0.4;
}
}
#keyframes moveangle1 {
0% {
border-width: 200px 0 0 1440px;
opacity: 0.7;
}
100% {
border-width: 400px 0 0 1000px;
opacity: 0.4;
}
}
<div class="angle-1">
</div>

Resources