trigger #keyframes animation, when you hover seperate object in CSS - css

What I am trying to do is when I :hover the trigger container, it should trigger the #keyframes rings on the spans, just like how it does it when you load the page.
I have a codepen link here: https://codepen.io/anon/pen/moERzj
.trigger img {
width: 140px;
border-radius: 100%;
padding: 2px;
}
.trigger {
margin: 0 auto;
position: relative;
}
.trigger > span {
border-radius: 100% / 100%;
position: absolute;
width: 140px;
height: 140px;
border: 2px solid #fff;
background: #333;
z-index: -1;
-webkit-animation: rings 1s;
-moz-animation: rings 1s;
-ms-animation: rings 1s;
-o-animation: rings 1s;
animation: rings 1s;
}
.trigger:hover > span {
-webkit-animation: rings 1s;
-moz-animation: rings 1s;
-ms-animation: rings 1s;
-o-animation: rings 1s;
animation: rings 1s;
}
.trigger > img:hover > span {
-webkit-animation: rings 1s;
-moz-animation: rings 1s;
-ms-animation: rings 1s;
-o-animation: rings 1s;
animation: rings 1s;
}
.trigger > span:nth-child(1) {
animation-delay: 0s;
}
.trigger > span:nth-child(2) {
animation-delay: 0.2s;
}
.trigger > span:nth-child(3) {
animation-delay: 0.4s;
}
#-webkit-keyframes rings {
0% {opacity: 0;transform: scale(1);}
70% {opacity: 1; transform: scale(1.3);}
100% {opacity: 0;transform: scale(1);}
}
#-moz-keyframes rings {
0% {opacity: 0;transform: scale(1);}
70% {opacity: 1;transform: scale(1.3);}
100% {opacity: 0;transform: scale(1);}
}
#-ms-keyframes rings {
0% {opacity: 0;transform: scale(1);}
70% {opacity: 1;transform: scale(1.3);}
100% {opacity: 0;transform: scale(1);}
}
#-o-keyframes rings {
0% {opacity: 0;transform: scale(1);}
70% {opacity: 1;transform: scale(1.3);}
100% {opacity: 0;transform: scale(1);}
}
#keyframes rings {
0% {opacity: 0;transform: scale(1);}
70% {opacity: 1;transform: scale(1.3);}
100% {opacity: 0;transform: scale(1);}
}
I just want to be able to trigger #keyframes rings on the spans, when I :hover something else, like the trigger div or img.

It is enough to add 'infinite' to your animation, so that it runs more than one time:
animation: rings 1s infinite;:
"use strict";
const element = document.getElementById("trigger");
element.addEventListener("mouseover", function(e){
element.classList.remove("animated");
void element.offsetWidth;
element.classList.add("animated");
}, false);
body { background: #333;}
#trigger {
margin: 60px auto;
padding: 30px;
position: relative;
border: 2px solid red;
width: 300px;
text-align: center;
}
#trigger * {
pointer-events: none;
}
#trigger img {
width: 140px;
border-radius: 100%;
padding: 2px;
}
#trigger.animated span {
border-radius: 100% / 100%;
position: absolute;
width: 140px;
height: 140px;
border: 2px solid #fff;
background: #333;
z-index: -1;
animation: rings 1s;
}
#trigger span:nth-child(1) {
animation-delay: 0s;
}
#trigger span:nth-child(2) {
animation-delay: 0.2s;
}
#trigger span:nth-child(3) {
animation-delay: 0.4s;
}
#keyframes rings {
0% {
opacity: 0;
transform: scale(1);
}
70% {
opacity: 1;
transform: scale(1.3);
}
100% {
opacity: 0;
transform: scale(1);
}
}
<div id="trigger" class="animated">
<span></span>
<span></span>
<span></span>
<img src="https://picsum.photos/140/140" alt="some pic">
</div>

I have done a tricky way which makes the run animation on hover smoothly but when you take moues out it does not end smoothly, however it full fill one thing animation on hover. One thing i noticed that .trigger img:hover span will perform nothing as spans are not child to image. Please check below pin:
Animation on hover

Related

pausing an animation at a particular time and resuming

I want the square to start playing the animation for 5s then, stop playing the animation for 3s and then continue. Is this possible only using CSS3?
.box {
background-color: rebeccapurple;
border-radius: 10px;
width: 100px;
height: 100px;
animation-name: rotate;
animation-duration: 20s;
animation-play-state: running;
animation-iteration-count:infinite;
}
#keyframes rotate {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
<div class="box"></div>
Since animation-duration is 20s, then in the #kayframes, 25% = 5s => 5% = 1s => 15% = 3s (between 25% - 40%)
.box {
background-color: rebeccapurple;
border-radius: 10px;
width: 100px;
height: 100px;
animation: rotate 20s infinite;
}
#keyframes rotate {
0% {
transform: rotate(0);
}
25% {
transform: rotate(90deg);
}
40% {
transform: rotate(90deg);
}
100%{
transform: rotate(360deg);
}
}
<div class="box"></div>

CSS3 keyframe jumps to end of animation without animating

In the linked fiddle, an element has two animations.
https://jsfiddle.net/ccqpLa6L/1/
Below is a capture of the CSS:
#-webkit-keyframes slideInLeft { 0% { transform: translateX(-200px); } 100% { transform: translateX(0); } }
#-webkit-keyframes slideOutLeft { 0% { transform: translateX(0); } 100% { transform: translateX(100px); }}
.element {
width: 250px;
height: 75px;
background-color: dimgrey;
right: 0;
margin-bottom: 10px;
border-radius: 5px;
-webkit-animation: slideInLeft 1s forwards, slideOutLeft 2s forwards;
-webkit-animation-delay: 0s, 1s;
}
The first animation executes without an issue, but the second animation jumps to the end of its animation without any interstitial frames.
Why?
While I'm not exactly sure why the animation wasn't running properly, I was able to achieve the desired effect using spaced out percentages in one keyframe:
https://jsfiddle.net/ccqpLa6L/5/
#-webkit-keyframes slideInLeft {
0% {
transform: translateX(-200px);
}
25% {
transform: translateX(0);
}
50% {
transform: translateX(0);
}
100% {
-webkit-transform: translateX(100px);
}
}
.element {
width: 250px;
height: 75px;
background-color: dimgrey;
margin-bottom: 10px;
border-radius: 5px;
-webkit-animation: slideInLeft 4s forwards;
}

Snake loader css animation keyframes doesn't work

Im trying to make a snake loader spinner with css using keyframes animation but i don't know it doesn't work
someone can help?
here the fiddle:
https://jsfiddle.net/fs6kafsn/
#keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.spinner {
display: block;
margin: 50px;
height: 28px;
width: 28px;
animation: rotate 0.8s infinitelinear!important;
-webkit-animation: rotate 0.8s infinitelinear!important;
border: 8px solid red;
border-right-color: transparent;
border-radius: 50%;
position:relative;
}
thanks in advance
You need to add prefixing to your keyframes as well.
fiddle demo
#-webkit-keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
This would need to be prefixed with -moz- as well for firefox compatibility.
Note
the unprefixed version should always be placed after the prefixed versions.
Full Demo
.spinner {
display: block;
margin: 50px;
height: 28px;
width: 28px;
-webkit-animation: rotate 0.8s infinite linear !important;
-moz-animation: rotate 0.8s infinite linear !important;
animation: rotate 0.8s infinite linear !important;
border: 8px solid red;
border-right-color: transparent;
border-radius: 50%;
position:relative;
}
#-webkit-keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#-moz-keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<div class="spinner">
</div>
For webkit based browser like chrome you need #-webkit-keyframes and for Mozilla firefox you need #-moz-keyframes
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#-webkit-keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#-moz-keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.spinner {
display: block;
margin: 50px;
height: 28px;
width: 28px;
animation: spin 0.8s infinite linear!important;
-webkit-animation: spin 0.8s infinite linear!important;
border: 8px solid red;
border-right-color: transparent;
border-radius: 50%;
position:relative;
}
<div class="spinner">
</div>
I changed your fiddle. Here is the working animation: fiddle:
Code:
#-moz-keyframes myanimation /* Firefox */
{
0% {transform: rotate(0deg);}
100% {transform: rotate(360deg);}
}
#-webkit-keyframes myanimation /* Safari and Chrome */
{
0% {transform: rotate(0deg);}
100% {transform: rotate(360deg);}
}
.spinner {
display: block;
margin: 50px;
height: 28px;
width: 28px;
animation:myfirst 5s;
-moz-animation:myanimation 0.8s infinite linear; /* Firefox */
-webkit-animation:myanimation 0.8s infinite linear; /* Safari and Chrome */
border: 8px solid red;
border-right-color: transparent;
border-radius: 50%;
position:relative;
}

Animation not working in CSS

I am using Codepen and would like one of my elements to fade in and out. I can't find any errors in my code but it is still not working. Thanks for any help!
The item is a little logo box that you press to open up a new window with text. It currently changes on mouseover but I would also like to make it fade in and out so that people know they need to click it.
Thanks Danko, I got it working now! Can't believe the issue was that simple haha :)
.mainlink a:link, a:visited {
display: block;
background: url(http://i.imgur.com/E3EQRWV.jpg?2);
background-size:cover;
width: 50px;
height: 50px;
border-radius: 50%;
position: relative;
margin-left: auto;
margin-right: auto;
border: 2px solid black;
animation: fadin 3s infinite alternate;
-webkit-animation: fadin 3s infinite alternate;
-moz-animation: fadin 3s infinite alternate;
-o-animation: fadin 3s infinite alternate;}
#keyframes fadin {
0% {opacity: 100%;}
50% {opacity: 50%;}
100% {opacity: 0%;}}
#-webkit-keyframes fadin{
0% {opacity: 100%;}
50% {opacity: 50%;}
100% {opacity: 0%;}}
#-moz-keyframes fadin{
0% {opacity: 100%;}
50% {opacity: 50%;}
100% {opacity: 0%;}}
#-o-keyframes fadin{
0% {opacity: 100%;}
50% {opacity: 50%;}
100% {opacity: 0%;}}
The problem here is opacity doesn't accept % as unit value. Change it to a value between
1 and 0 Where 1 = 100% and 0 = 0%
Try this:
#keyframes fadin {
0% {opacity: 1;}
100% {opacity: 0;}
}
.mainlink a {
display: block;
background: url(http://i.imgur.com/E3EQRWV.jpg?2);
background-size: cover;
width: 50px;
height: 50px;
border-radius: 50%;
position: relative;
margin-left: auto;
margin-right: auto;
border: 2px solid black;
animation: fadin 3s infinite alternate;
-webkit-animation: fadin 3s infinite alternate;
-moz-animation: fadin 3s infinite alternate;
-o-animation: fadin 3s infinite alternate;
}
#keyframes fadin {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#-webkit-keyframes fadin {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#-moz-keyframes fadin {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#-o-keyframes fadin {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
<div class="mainlink">
</div>

CSS 3 float text top left in keyframe animation

I've tried many different ways to add text to this keyframe animation, but the problem is that it messes up one of the animations when I include the div containing the text. Ideally, I want the text to be center and top or center and top left, but when I get it there, it throws off the last span in the animation. How can I edit the class waitingtext so that it doesn't interfere with the animation?
Site where I got the css
HTML
<div class="main-loading" ng-show="mainloading">
<div class="waitingtext">My text</div>
<span class="main-loading"></span><!--
--><span></span><!--
--><span></span><!--
--><span></span><!--
--><span></span>
</div>
CSS
.waitingtext {
color:#FFF;
position: absolute;
z-index: -1;
line-height: 60px!important;
float: left;
margin-top: 5px;
}
div.main-loading
{
background: #1b7817;
opacity:.9;
position: absolute;
width: 400px;
height: 300px;
top: 50%;
left: 50%;
margin: -150px 0 0 -200px;
text-align: center;
border:1px solid #dcdcdc;-moz-border-radius:6px;-webkit-border-radius:6px;border-radius:6px; padding-left: 5px
}
div.main-loading
{
position: absolute;
height: 300px;
top: 50%;
left: 50%;
line-height: 300px;
text-align: center;
clear: both;
}
.main-loading span
{
display: inline-block;
width: 10px;
height: 10px;
margin: 145px 3px 0;
background: rgba(255,255,255,0.25);
border-radius: 50%;
transform: translateY(0);
-moz-transform: translateY(0);
-webkit-transform: translateY(0);
animation: wave 2s infinite ease-in-out;
-moz-animation: wave 2s infinite ease-in-out;
-webkit-animation: wave 2s infinite ease-in-out;
}
#keyframes wave
{
0%, 60%, 100%
{
background: rgba(255,255,255,0.25);
transform: translateY(0);
-moz-transform: translateY(0);
}
20%
{
background: rgba(255,255,255,0.75);
transform: translateY(13px);
-moz-transform: translateY(13px);
}
40%
{
background: rgba(255,255,255,0.75);
transform: translateY(-13px);
-moz-transform: translateY(-13px);
}
}
#-webkit-keyframes wave
{
0%, 60%, 100%
{
background: rgba(255,255,255,0.25);
transform: translateY(0);
-webkit-transform: translateY(0);
}
20%
{
background: rgba(255,255,255,0.75);
transform: translateY(13px);
-webkit-transform: translateY(13px);
}
40%
{
background: rgba(255,255,255,0.75);
transform: translateY(-13px);
-webkit-transform: translateY(-13px);
}
}
.main-loading span:nth-child(1)
{
animation-delay: 0s;
-moz-animation-delay: 0s;
-webkit-animation-delay: 0s;
}
.main-loading span:nth-child(2)
{
animation-delay: 0.1s;
-moz-animation-delay: 0.1s;
-webkit-animation-delay: 0.1s;
}
.main-loading span:nth-child(3)
{
animation-delay: 0.2s;
-moz-animation-delay: 0.2s;
-webkit-animation-delay: 0.2s;
}
.main-loading span:nth-child(4)
{
animation-delay: 0.3s;
-moz-animation-delay: 0.3s;
-webkit-animation-delay: 0.3s;
}
.main-loading span:nth-child(5)
{
animation-delay: 0.4s;
-moz-animation-delay: 0.4s;
-webkit-animation-delay: 0.4s;
}
This has nothing to do with positioning but everything to do with your CSS selectors
:nth-child() (what you were using) counts all of the children of the parent, including the div you added. What you need is nth-of-type(), which only counts the spans
Demo

Resources