I'm trying to use this code for a website.
I'm using CSS3 Keyframe and animations for it with a simple list
#animation ul { /* The list with elements */
position: relative;
text-align: center;
width: 200px;
}
#animation li { /* Common styles for the list elements */
position: absolute;
left:0;
top:0;
width: 100%;
opacity: 0;
padding: 10px;
}
#animation li:nth-of-type(1) { /* First element of the list */
background-color: lightgreen;
-webkit-animation: fadein 6s ease-in-out -4s infinite alternate; /* delay = -duration * 66%. Note the negative delay to skip the "keyframes delay" */
-moz-animation: fadein 6s ease-in-out -4s infinite alternate;
animation: fadein 6s ease-in-out -4s infinite alternate;
}
#animation li:nth-of-type(2) { /* Second element of the list */
background-color: yellow;
-webkit-animation: fadein 6s ease-in-out 0s infinite alternate;
-moz-animation: fadein 6s ease-in-out 0s infinite alternate;
animation: fadein 6s ease-in-out 0s infinite alternate;
}
#animation li:nth-of-type(3) { /* Third element of the list */
background-color: lightblue;
-webkit-animation: fadein 6s ease-in-out 4s infinite alternate; /* delay = duration * 66% */
-moz-animation: fadein 6s ease-in-out 4s infinite alternate;
animation: fadein 6s ease-in-out 4s infinite alternate;
}
/* Defines the animation keyframes */
#-webkit-keyframes fadein {
0% { /* "Delay" of the animation - 66% of the duration time (100 - 100/number of elements) */
opacity: 0;
}
66% { /* Actual beginning of the fade in animation */
opacity: 0;
}
76% { /* The fade in animation takes 10% of the duration time */
opacity: 1;
}
100% {
opacity: 1;
}
}
#-moz-keyframes fadein {
0% {
opacity: 0;
}
66% {
opacity: 0;
}
76% {
opacity: 1;
}
100% {
opacity: 1;
}
}
#keyframes fadein {
0% {
opacity: 0;
}
66% {
opacity: 0;
}
76% {
opacity: 1;
}
100% {
opacity: 1;
}
}
<div id="animation">
<ul>
<li>This is</li>
<li>CSS3 looped</li>
<li>animation</li>
</ul>
</div>
I want to set 5 elements instead of 3 but when I edit this code with 5 elements, it's not the same result..
Thanks for the help !
You have to change the time intervels that you have mentioned . Check the below code.
#animation ul { /* The list with elements */
position: relative;
text-align: center;
width: 200px;
}
#animation li { /* Common styles for the list elements */
position: absolute;
left:0;
top:0;
width: 100%;
opacity: 0;
padding: 10px;
}
#animation li:nth-of-type(1) { /* First element of the list */
background-color: lightgreen;
-webkit-animation: fadein 6s ease-in-out -4s infinite alternate; /* delay = -duration * 66%. Note the negative delay to skip the "keyframes delay" */
-moz-animation: fadein 6s ease-in-out -4s infinite alternate;
animation: fadein 6s ease-in-out -4s infinite alternate;
}
#animation li:nth-of-type(2) { /* Second element of the list */
background-color: yellow;
-webkit-animation: fadein 6s ease-in-out 0s infinite alternate;
-moz-animation: fadein 6s ease-in-out 0s infinite alternate;
animation: fadein 6s ease-in-out 0s infinite alternate;
}
#animation li:nth-of-type(3) { /* Third element of the list */
background-color: lightblue;
-webkit-animation: fadein 6s ease-in-out 4s infinite alternate; /* delay = duration * 66% */
-moz-animation: fadein 6s ease-in-out 4s infinite alternate;
animation: fadein 6s ease-in-out 4s infinite alternate;
}
#animation li:nth-of-type(4) { /* fourth element of the list */
background-color: pink;
-webkit-animation: fadein 6s ease-in-out 8s infinite alternate; /* delay = duration * 66% */
-moz-animation: fadein 6s ease-in-out 8s infinite alternate;
animation: fadein 6s ease-in-out 8s infinite alternate;
}
#animation li:nth-of-type(5) { /* fifth element of the list */
background-color: red;
-webkit-animation: fadein 6s ease-in-out 12s infinite alternate;
-moz-animation: fadein 6s ease-in-out 12s infinite alternate;
animation: fadein 6s ease-in-out 12s infinite alternate;
}
/* Defines the animation keyframes */
#-webkit-keyframes fadein {
0% { /* "Delay" of the animation - 66% of the duration time (100 - 100/number of elements) */
opacity: 0;
}
66% { /* Actual beginning of the fade in animation */
opacity: 0;
}
76% { /* The fade in animation takes 10% of the duration time */
opacity: 1;
}
100% {
opacity: 1;
}
}
#-moz-keyframes fadein {
0% {
opacity: 0;
}
66% {
opacity: 0;
}
76% {
opacity: 1;
}
100% {
opacity: 1;
}
}
#keyframes fadein {
0% {
opacity: 0;
}
66% {
opacity: 0;
}
76% {
opacity: 1;
}
100% {
opacity: 1;
}
}
<div id="animation">
<ul>
<li>This is</li>
<li>CSS3 looped</li>
<li>animation</li>
<li>example</li>
<li>here</li>
</ul>
</div>
Related
I'm trying to animate a certain div opacity from 0 to 0.6, but it seems that at the end of the animation it jumps to 1.
What am I missing?
#test {
width: 200px;
height: 200px;
background-color: #900;
animation: fadein 2s;
-moz-animation: fadein 2s;
-webkit-animation: fadein 2s;
-o-animation: fadein 2s;
}
#keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 0.5;
}
}
#-moz-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 0.5;
}
}
#-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 0.5;
}
}
#-o-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 0.5;
}
}
<div id="test"></div>
You need to specify animation-fill-mode: forwards if you want the element's CSS to remain at the last step of the animation.
https://developer.mozilla.org/en-US/docs/Web/CSS/animation-fill-mode
Forwards: The target will retain the computed values set by the last keyframe encountered during execution.
#test {
width: 200px;
height: 200px;
background-color: #900;
animation: fadein 2s forwards;
-moz-animation: fadein 2s forwards;
-webkit-animation: fadein 2s forwards;
-o-animation: fadein 2s forwards;
}
#keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 0.5;
}
}
#-moz-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 0.5;
}
}
#-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 0.5;
}
}
#-o-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 0.5;
}
}
<div id="test"></div>
Have you tried setting the opacity on the element you are animating to the final value?
I believe the rules in a CSS animation stop applying when the animation finishes. I would guess it is animating from 0 to 0.5 and then reverting to 1, 1 being the default opacity since you don't have an opacity specified on the element itself.
I hope this helps!
How can I make a button fade in/out on a loop while moving down with css animations? so far I got the fade in/out working fine. But I cant get them both to work at the same time.
<div class="down-arrow"><button class="down-button animate-flicker" type="button">VVV</button></div>
#keyframes flickerAnimation {
from {top:0px; opacity: 0; }
to {top:200px;}
}
#-o-keyframes flickerAnimation {
from {top:0px; opacity: 0; }
to {top:200px;}
}
#-moz-keyframes flickerAnimation {
from {top:0px; opacity: 0; }
to {top:200px;}
}
#-webkit-keyframes flickerAnimation {
from {top:0px; opacity: 0; }
to {top:200px;}
}
.animate-flicker {
animation: flickerAnimation 1s infinite alternate;
-webkit-animation: flickerAnimation 1s infinite alternate;
-moz-animation: flickerAnimation 1s infinite alternate;
-o-animation: flickerAnimation 1s infinite alternate;
}
https://jsfiddle.net/ywn9w5L9/3/
Working JSFiddle.
You just need to add a position attribute to your animate-flicker class in your existing css.
Check my code snippet below :
#
keyframes flickerAnimation {
0 % {
top: 0;
opacity: 0;
}
100 % {
top: 200px;
opacity: 1;
}
}
# - o - keyframes flickerAnimation {
from {
top: 0px;
opacity: 0;
}
to {
top: 200px;
}
}
# - moz - keyframes flickerAnimation {
from {
top: 0px;
opacity: 0;
}
to {
top: 200px;
}
}
# - webkit - keyframes flickerAnimation {
from {
top: 0px;
opacity: 0;
}
to {
top: 200px;
}
}
.animate - flicker {
position: absolute;
animation: flickerAnimation 1s infinite alternate; - webkit - animation: flickerAnimation 1s infinite alternate; - moz - animation: flickerAnimation 1s infinite alternate; - o - animation: flickerAnimation 1s infinite alternate;
}
<div class="down-arrow">
<button class="down-button animate-flicker" type="button">VVV</button>
</div>
Hope this helps.
I'm trying to, on li:hover, have one child <div> animate its width, at x seconds, from 0 to 100% and then a given number of seconds later animate another div the exact same way.
This is my code and it isn't working the way that I want it to.
li {
margin-bottom: -1px;
#top, #bottom {
height: 1px;
width: 0;
display: block;
background: $white;
}
#bottom {
-o-transition:.25s;
-ms-transition:.25s;
-moz-transition:.25s;
-webkit-transition:.25s;
transition:.25s;
}
#top {
-moz-animation: fadein 3s ease-in 3s forwards; /* Firefox */
-webkit-animation: fadein 3s ease-in 3s forwards; /* Safari and Chrome */
-o-animation: fadein 3s ease-in 3s forwards; /* Opera */
animation: fadein 3s ease-in 3s forwards;
}
&:hover {
#bottom {
-o-transition:.25s;
-ms-transition:.25s;
-moz-transition:.25s;
-webkit-transition:.25s;
transition:.25s;
width: 100%;
}
#top {
-moz-animation: fadein 3s ease-in 3s forwards; /* Firefox */
-webkit-animation: fadein 3s ease-in 3s forwards; /* Safari and Chrome */
-o-animation: fadein 3s ease-in 3s forwards; /* Opera */
animation: fadein 3s ease-in 3s forwards;
width: 100%;
}
}
}
Could someone explain to me what it is I am doing wrong?
You cannot use the animation property without defining keyframes.
I’m trying to get some (will be images) blocks to fade in pause for a few seconds and then fade out....
I’ve got it so far but it doesn’t seem to want to stay faded out and i’m unsure where i’m going wrong.
After its faded out it then shows up again.
I have a fiddle which shows it very basicly.
/* Defines the animation keyframes */
#-webkit-keyframes fadein {
0% {
opacity: 0;
}
72% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#-moz-keyframes fadein {
0% {
opacity: 0;
}
72% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fadein {
0% {
opacity: 0;
}
72% {
opacity: 0;
}
100% {
opacity: 1;
}
}
/* Defines the animation keyframes */
#-webkit-keyframes fadeOut {
0% {
opacity: 1;
}
72% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#-moz-keyframes fadeOut {
0% {
opacity: 1;
}
72% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#keyframes fadeOut {
0% {
opacity: 1;
}
72% {
opacity: 0;
}
100% {
opacity: 0;
}
}
.get{
-webkit-animation: fadein 1.9s ease-in-out 0s 1,
fadeOut 1.9s ease-in-out 5s 1 ;
-moz-animation: fadein 1.9s ease-in-out 0s 1,
fadeOut 1.9s ease-in-out 5s 1 ;
animation: fadein 1.9s ease-in-out 0s 1,
fadeOut 1.9s ease-in-out 5s 1 ;
background-color:red;
}
.give{
-webkit-animation: fadein 2.8s ease-in-out both 0s 1,
fadeOut 1.9s ease-in-out 8s 1 ; ;
-moz-animation: fadein 2.8s ease-in-out both 0s 1,
fadeOut 1.9s ease-in-out 8s 1 ;
animation: fadein 2.8s ease-in-out both 0s 1,
fadeOut 1.9s ease-in-out 8s 1 ;
background-color:green;
}
Use a single animation ...
*{
margin:0;
padding:0;
}
.block{
width:100px;
height:100px
display:block;
height:100px;
}
#keyframes fadein {
0%, 100% {
opacity: 0;
}
72% {
opacity: 1;
}
}
.get{
opacity: 0;
animation: fadein 2s ease-in-out 0s 1;
background-color:red;
}
.give{
opacity: 0;
animation: fadein 3s ease-in-out both 1s 1;
background-color:green;
}
<script src="//cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="block get">Get</div>
<div class="block give">Give</div>
So I'm trying to animate some text dropping down once its finished animating.
The problem is it just disappears after it's finished, even though I set the opacity to 1# 100%.
/* text animation */
#-webkit-keyframes textAnimation {
0% {
opacity: 0;
-webkit-transform: translateY(-200%);
}
10% {
opacity: 1;
-webkit-transform: translateY(0%);
}
20% {
opacity: 1;
-webkit-transform: translateY(0%);
}
100% {
opacity: 1;
-webkit-transform: translateY(0%);
}
}
.text-animation {
z-index: 1000;
width: 100%;
text-align: center;
opacity: 0;
-webkit-animation: textAnimation 2s linear 2s;
-moz-animation: textAnimation 2s linear 2s;
-o-animation: textAnimation 2s linear 2s;
-ms-animation: textAnimation 2s linear 2s;
animation: textAnimation 2s linear 2s;
-webkit-animation-iteration-count: 1;
-webkit-animation-delay: 1s;
-moz-animation-delay: 1s;
-o-animation-delay: 1s;
-ms-animation-delay: 1s;
animation-delay: 1s;
}
/* text animation */
I just don't understand what the problem is here...
This worked for me.
If you set the end state in the class and not add a delay.
#-webkit-keyframes textAnimation {
0% { opacity: 0; -webkit-transform: translateY(-200%); }
33% { opacity: 1; -webkit-transform: translateY(-200%); }
100% { opacity: 1; -webkit-transform: translateY(0%); }
}
.text-animation {
color:#fff;
font-size:32px;
width: 100%;
text-align: center;
opacity: 1;
-webkit-animation: textAnimation 3s linear;
-moz-animation: textAnimation 3s linear;
-o-animation: textAnimation 3s linear;
-ms-animation: textAnimation 3s linear;
animation: textAnimation 3s linear;
}
In you .text-animation declaration add this :
-webkit-animation-fill-mode: forwards;
Thanks to it, your animation will stay to the last keyframe state. (here, opacity 0).
You can see the result here : http://codepen.io/joe/pen/CkbcL
Source : https://developer.mozilla.org/en-US/docs/CSS/animation-fill-mode