2 css animation call for 1 element - css

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}
}

Related

The vh unit doesn't seem to work with transform: translateY

I have 2 half-page-sized overlays that translate the opposite ways to give the illusion that the screen is opening up. In addition, I want them to stop at about 8% from the viewport top or bottom and not disappear entirely. It doesn't really work with % because on mobile devices with bars and other UI they are get cut off. I have tried to use vh but it just disappears into the viewport edges.
/*default animations*/
.main-transition-overlay1 {
position: fixed;
background-color: black;
z-index: 10;
height: 50vh;
top: 0;
left: 0;
width: 100%;
animation-name: page-transition-top;
animation-duration: 750ms;
animation-timing-function: ease-in;
animation-fill-mode: forwards;
animation-delay: 2s;
border-bottom: 4px solid #fff;
color: #fff;
box-shadow: 0 0px 1.5px #99ffff, 0 0px 2.5px #99ffff, 0 0px 5.5px #99ffff, 0 0px 10px #0cbfe9, 0 0px 20px #0cbfe9, 0 0px 22px #0cbfe9, 0 0px 25px #0cbfe9, 0 0px 36px #0cbfe9;
}
#keyframes page-transition-top {
from {
transform: translateY(0);
}
to {
transform: translateY(-92vh);
}
}
.main-transition-overlay2 {
position: fixed;
background-color: black;
z-index: 10;
height: 50vh;
top: 50vh;
left: 0;
width: 100%;
animation-name: page-transition-bottom;
animation-duration: 750ms;
animation-timing-function: ease-in;
animation-fill-mode: forwards;
animation-delay: 2s;
border-top: 4px solid #fff;
color: #fff;
box-shadow: 0 0 1.5px #99ffff, 0 0 2.5px #99ffff, 0 0 5.5px #99ffff, 0 0 10px #0cbfe9, 0 0 20px #0cbfe9, 0 0 22px #0cbfe9, 0 0 25px #0cbfe9, 0 0 36px #0cbfe9;
}
#keyframes page-transition-bottom {
from {
transform: translateY(0);
}
to {
transform: translateY(92vh);
}
}
<!--main screen transition overlay-->
<div>
<div class="main-transition-overlay1"></div>
<div class="main-transition-overlay2"></div>
</div>
Your transform value for that should be translateY(42vh) (and -42vh) instead of +/-92vh, that's the amount the elements move up/down:
/*default animations*/
.main-transition-overlay1 {
position: fixed;
background-color: black;
z-index: 10;
height: 50vh;
top: 0;
left: 0;
width: 100%;
animation-name: page-transition-top;
animation-duration: 750ms;
animation-timing-function: ease-in;
animation-fill-mode: forwards;
animation-delay: 2s;
border-bottom: 4px solid #fff;
color: #fff;
box-shadow: 0 0px 1.5px #99ffff, 0 0px 2.5px #99ffff, 0 0px 5.5px #99ffff, 0 0px 10px #0cbfe9, 0 0px 20px #0cbfe9, 0 0px 22px #0cbfe9, 0 0px 25px #0cbfe9, 0 0px 36px #0cbfe9;
}
#keyframes page-transition-top {
from {
transform: translateY(0);
}
to {
transform: translateY(-42vh);
}
}
.main-transition-overlay2 {
position: fixed;
background-color: black;
z-index: 10;
height: 50vh;
top: 50vh;
left: 0;
width: 100%;
animation-name: page-transition-bottom;
animation-duration: 750ms;
animation-timing-function: ease-in;
animation-fill-mode: forwards;
animation-delay: 2s;
border-top: 4px solid #fff;
color: #fff;
box-shadow: 0 0 1.5px #99ffff, 0 0 2.5px #99ffff, 0 0 5.5px #99ffff, 0 0 10px #0cbfe9, 0 0 20px #0cbfe9, 0 0 22px #0cbfe9, 0 0 25px #0cbfe9, 0 0 36px #0cbfe9;
}
#keyframes page-transition-bottom {
from {
transform: translateY(0);
}
to {
transform: translateY(42vh);
}
}
<!--main screen transition overlay-->
<div>
<div class="main-transition-overlay1"></div>
<div class="main-transition-overlay2"></div>
</div>

Bootstrap button & loading animation

I've added loading animation to the bootstrap button, and it is not showing correctly.
I've added a div to the button with the class "loader". But the loading animation is showing under the button.
How can I fix it with responsive design
Here is codepen: https://codepen.io/ayxano/pen/oNNxgQx
.loader,
.loader:before,
.loader:after {
border-radius: 50%;
width: 2.5em;
height: 2.5em;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation: load7 1.8s infinite ease-in-out;
animation: load7 1.8s infinite ease-in-out;
}
.loader {
color: #ffffff;
font-size: 10px;
position: relative;
text-indent: -9999em;
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
.loader:before,
.loader:after {
content: '';
position: absolute;
top: 0;
}
.loader:before {
left: -3.5em;
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.loader:after {
left: 3.5em;
}
#-webkit-keyframes load7 {
0%,
80%,
100% {
box-shadow: 0 2.5em 0 -1.3em;
}
40% {
box-shadow: 0 2.5em 0 0;
}
}
#keyframes load7 {
0%,
80%,
100% {
box-shadow: 0 2.5em 0 -1.3em;
}
40% {
box-shadow: 0 2.5em 0 0;
}
}
The issue is with the box-shadow. You are using a y-offset of 2.5em.
Try below CSS in this particular case:
.center-block.loader {
top: -2.5em;
}

How to make this design responsive?

I have tried to make an animation using CSS keyframes, but the design is breaking. How can I make it responsive without writing media queries, as it's just a simple animation code?
div {
font-family: "Comic Sans MS", sans-serif;
margin-left: 200px;
margin-top: 200px;
}
span {
color: white;
font-size: 35px;
padding: 14px 25px;
margin: 5px;
border-radius: 10px;
display: inline-block;
animation: move 0.8s infinite linear;
}
#keyframes move {
0% {
transform: translateY(0px);
opacity: 1.0;
}
50% {
transform: translateY(-50px);
opacity: 0.5;
}
100% {
transform: translateY(0px);
opacity: 1.0;
}
}
span:nth-child(1) {
animation-delay: 0.1s;
background-color: red;
box-shadow: 5px 5px 0 black;
}
span:nth-child(2) {
animation-delay: 0.2s;
background-color: blue;
box-shadow: 5px 5px 0 black;
}
span:nth-child(3) {
animation-delay: 0.3s;
background-color: green;
box-shadow: 5px 5px 0 black;
}
span:nth-child(4) {
animation-delay: 0.4s;
background-color: orangered;
box-shadow: 5px 5px 0 black;
}
span:nth-child(5) {
animation-delay: 0.5s;
background-color: springgreen;
box-shadow: 5px 5px 0 black;
}
span:nth-child(6) {
animation-delay: 0.6s;
background-color: blueviolet;
box-shadow: 5px 5px 0 black;
}
span:nth-child(7) {
animation-delay: 0.7s;
background-color: purple;
box-shadow: 5px 5px 0 black;
}
<div>
<span>W</span>
<span>E</span>
<span>L</span>
<span>C</span>
<span>O</span>
<span>M</span>
<span>E</span>
</div>
Without using a media query, you are limited to what you can do, but in this example, I've removed your set margin-left value and used a percentage instead and made the containing div a percentage width. I've also made the parent div a flex container - this will make sure things have a harder time wrapping on smaller screens.
I then used vw units for the font-size, so it will scale with the window width. Also the padding on the boxes needs to be set to percentages. You can play with it here:
https://jsfiddle.net/disinfor/s5hkyr2f/3/
div {
font-family: "Comic Sans MS", sans-serif;
margin: 200px auto 0;
width: 90%;
display: flex;
justify-content: center;
}
span {
color: white;
font-size: 4vw;
padding: 2% 3%;
margin: 5px;
border-radius: 10px;
display: inline-block;
animation: move 0.8s infinite linear;
}
#keyframes move {
0% {
transform: translateY(0px);
opacity: 1.0;
}
50% {
transform: translateY(-50px);
opacity: 0.5;
}
100% {
transform: translateY(0px);
opacity: 1.0;
}
}
span:nth-child(1) {
animation-delay: 0.1s;
background-color: red;
box-shadow: 5px 5px 0 black;
}
span:nth-child(2) {
animation-delay: 0.2s;
background-color: blue;
box-shadow: 5px 5px 0 black;
}
span:nth-child(3) {
animation-delay: 0.3s;
background-color: green;
box-shadow: 5px 5px 0 black;
}
span:nth-child(4) {
animation-delay: 0.4s;
background-color: orangered;
box-shadow: 5px 5px 0 black;
}
span:nth-child(5) {
animation-delay: 0.5s;
background-color: springgreen;
box-shadow: 5px 5px 0 black;
}
span:nth-child(6) {
animation-delay: 0.6s;
background-color: blueviolet;
box-shadow: 5px 5px 0 black;
}
span:nth-child(7) {
animation-delay: 0.7s;
background-color: purple;
box-shadow: 5px 5px 0 black;
}
<div>
<span>W</span>
<span>E</span>
<span>L</span>
<span>C</span>
<span>O</span>
<span>M</span>
<span>E</span>
</div>

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.

How to bound CSS3 animation to class

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>

Resources