keyframe loading animation when loading page - html

I am trying to load an unordered list with animation using CSS3 keyframe.
My problem is the list get loaded before the animation begun.
And I want it to load only after the animation.
here is a result of what I achieved so far http://jsbin.com/agelix/1/edit
HTML
<ul
class="loadingdiv" >
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
CSS
.loadingdiv li{
-moz-animation: loading 1s alternate;
}
.loadingdiv li:nth-of-type(2) {
-moz-animation-delay: 0.4s;
}
.loadingdiv li:nth-of-type(3) {
-moz-animation-delay: 0.6s;
}
.loadingdiv li:nth-of-type(4) {
-moz-animation-delay: 0.8s;
}
.loadingdiv li:nth-of-type(5) {
-moz-animation-delay: 0.9s;
}
#-moz-keyframes loading {
0% {-moz-transform: translateZ(0); opacity:0}
}

OK, after lot click click click... and some info from css3files.com, It worked.
DEMO: http://jsbin.com/ehujis/1/edit
her is what I did.
HTML:
<ul>
<li class="box fade-in">1</li>
<li class="box fade-in">2</li>
<li class="box fade-in">3</li>
<li class="box fade-in">4</li>
</ul>
CSS:
/* make keyframes that tell the start state and the end state of our object */
#keyframes fadeIn {
from { opacity:0; }
to { opacity:1; } }
.fade-in {
opacity:0; /* make things invisible upon start */
animation:fadeIn ease-out 3s;
animation-fill-mode:forwards;
animation-duration:.8s;
}
li:nth-of-type(1) {
animation-delay: 0.6s;
}
li:nth-of-type(2) {
animation-delay: 1.3s;
}
li:nth-of-type(3) {
animation-delay: 2s;
}
li:nth-of-type(4) {
animation-delay: 2.7s;
}
Note: this code is based from the graphicfusiondesign.com article: Creating fancy CSS3 fade in animations on page load
here is a demo

Related

Elements in list fading in at unexpected times

I am trying to load in separate elements in a list at different times.
The bird top left should be first, followed by the background and then the other elements.
https://imgur.com/a/Z4vKcEv
As you can see in this gif, the elements are fading in at times different than i expected. Anyone know why?
EDIT: If GIF does not load, the last element in the list loads first, and then the other elements load in order.
Here is my code:
HTML:
<ul class="anim">
<li class="logo">
<img src="imgs/bird.jpg">
</li>
<li class="fullscreen-bg">
<img class="fullscreen-bg__img" src="imgs/rockymountains.jpg">
</li>
<li class="green1">
<h1>ESTUDO</h1>
</li>
<li class="green2">
<h1>ESTUDO E TRABALHO</h1>
</li>
<li class="green3">
<h1>IMIGRAÇÃO</h1>
</li>
</div>
<li class="red">
<h1>SEU SONHO, NOSSA MISSÃO</h1>
</li>
</ul>
CSS
/* TEXT ANIMATIONS */
li {
opacity: 0;
animation: fadeIn 3.5s 1;
animation-fill-mode: forwards;
}
.anim li:nth-child(1) { animation-delay: 1s }
.anim li:nth-child(2) { animation-delay: 1.5s }
.anim li:nth-child(3) { animation-delay: 2s }
.anim li:nth-child(4) { animation-delay: 2.8s }
.anim li:nth-child(5) { animation-delay: 3.4s }
/*...*/
#keyframes fadeIn {
0% {
opacity: 0.0;
}
100% {
opacity: 1.0;
}
}
/* END TEXT ANIMATIONS */
From what i can tell all the children in the list are set properly. Thanks in advance for your help.
You have 6 "li" elements in your source but you have only set animation-delay for 1-5, that is why the 6th "li" do not have delay and will display first. Add in 1 more delay for that element will make it OK:
li {
opacity: 0;
animation: fadeIn 3.5s 1s;
animation-fill-mode: forwards;
}
.anim li:nth-child(1) { animation-delay: 1s }
.anim li:nth-child(2) { animation-delay: 1.5s }
.anim li:nth-child(3) { animation-delay: 2s }
.anim li:nth-child(4) { animation-delay: 2.5s }
.anim li:nth-child(5) { animation-delay: 3s }
.anim li:nth-child(6) { animation-delay: 3.5s }
/*...*/
#keyframes fadeIn {
0% {
opacity: 0.0;
}
100% {
opacity: 1.0;
}
}

Animate multiple elements sequentially using only CSS3 + SASS [duplicate]

I was trying to make a gradual fadein using normal CSS and no jquery on a list so it can fade in one-by-one. However, I only know how to do it in a limited amount of list. How do I loop the css so no matter how much list I have it still works.
Here is what I have done:
.ladder {
opacity: 0;
-webkit-animation: fadeIn 0.9s 1;
animation: fadeIn 0.9s 1;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
.ladder:nth-child(5n+1) {
-webkit-animation-delay: 0.2s;
animation-delay: 0.2s;
}
.ladder:nth-child(5n+2) {
-webkit-animation-delay: 0.4s;
animation-delay: 0.4s;
}
.ladder:nth-child(5n+3) {
-webkit-animation-delay: 0.6s;
animation-delay: 0.6s;
}
.ladder:nth-child(5n+4) {
-webkit-animation-delay: 0.8s;
animation-delay: 0.8s;
}
.ladder:nth-child(5n+5) {
-webkit-animation-delay: 1.0s;
animation-delay: 1.0s;
}
#-webkit-keyframes fadeIn {
0% {
opacity: 0.0;
}
100% {
opacity: 1.0;
}
}
#keyframes fadeIn {
0% {
opacity: 0.0;
}
100% {
opacity: 1.0;
}
}
<li class="ladder">A</li>
<li class="ladder">B</li>
<li class="ladder">C</li>
<li class="ladder">D</li>
<li class="ladder">E</li>
My question: How to make the css to work on no matter how much list there is.
Here is an idea using CSS variable that allow you to reduce the code. It's not generic but it's more easier to append a simple inline CSS to each li than writing complex CSS:
.ladder {
opacity: 0;
animation: fadeIn 1s var(--d) forwards;
}
#keyframes fadeIn {
100% {
opacity: 1;
}
}
<ul>
<li style="--d:0s" class="ladder">A</li>
<li style="--d:0.2s" class="ladder">B</li>
<li style="--d:0.4s" class="ladder">C</li>
<li style="--d:0.6s" class="ladder">D</li>
<li style="--d:0.8s" class="ladder">E</li>
</ul>
Here is another idea where you can apply an animation on the ul:
ul {
position:relative;
}
ul:before {
content:"";
position:absolute;
top:-20px;
bottom:0;
left:0;
right:0;
background:linear-gradient(to bottom,transparent,#fff 20px);
animation:fadeIn 2s forwards
}
#keyframes fadeIn {
0% {
top:-10px;
}
100% {
top: 100%;
}
}
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
</ul>

CSS animation delay (img display time)

I've got this CSS:
#-webkit-keyframes sliderFadeInOut {
0% {
opacity:1;
}
17% {
opacity:1;
}
25% {
opacity:0;
}
92% {
opacity:0;
}
100% {
opacity:1;
}
}
#-moz-keyframes sliderFadeInOut {
0% {
opacity:1;
}
17% {
opacity:1;
}
25% {
opacity:0;
}
92% {
opacity:0;
}
100% {
opacity:1;
}
}
#-o-keyframes sliderFadeInOut {
0% {
opacity:1;
}
17% {
opacity:1;
}
25% {
opacity:0;
}
92% {
opacity:0;
}
100% {
opacity:1;
}
}
#keyframes sliderFadeInOut {
0% {
opacity:1;
}
17% {
opacity:1;
}
25% {
opacity:0;
}
92% {
opacity:0;
}
100% {
opacity:1;
}
}
#slider {
background-size: cover;
position: fixed;
top: 100px;
bottom: 0px;
height:calc(100%-135px);
width: 100%;
}
#slider img {
border: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
margin: 0px;
width: 100%;
height: 100%;
position:absolute;
left:0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
#slider img {
-webkit-animation-name: sliderFadeInOut;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 10s;
-moz-animation-name: sliderFadeInOut;
-moz-animation-timing-function: ease-in-out;
-moz-animation-iteration-count: infinite;
-moz-animation-duration: 8s;
-o-animation-name: sliderFadeInOut;
-o-animation-timing-function: ease-in-out;
-o-animation-iteration-count: infinite;
-o-animation-duration: 8s;
animation-name: sliderFadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 8s;
}
#slider img:nth-of-type(1) {
-webkit-animation-delay: 6s;
-moz-animation-delay: 6s;
-o-animation-delay: 6s;
animation-delay: 6s;
}
#slider img:nth-of-type(2) {
-webkit-animation-delay: 4s;
-moz-animation-delay: 4s;
-o-animation-delay: 4s;
animation-delay: 4s;
}
#slider img:nth-of-type(3) {
-webkit-animation-delay: 2s;
-moz-animation-delay: 2s;
-o-animation-delay: 2s;
animation-delay: 2s;
}
#slider img:nth-of-type(4) {
-webkit-animation-delay: 0;
-moz-animation-delay: 0;
-o-animation-delay: 0;
animation-delay: 0;
}
I'm learning CSS Animations, but I didn't find out how to set the display time of one image.
I tried to change the animation delay but that only causes trouble..
Do you have an idea how to do this ?
Best regards
There were several things that needed some attention. Here's how I accomplished it, though there are other ways.
For the animation itself:
#keyframes sliderFadeInOut {
0% {
opacity:0;
}
17% {
opacity:1;
}
25% {
opacity:1;
}
92% {
opacity:1;
}
100% {
opacity:0;
}
}
This causes the image to fade in, then fade out at whatever animation-duration we set.
Set the animation-iteration-count to 1, so the animation runs once.
animation-iteration-count: 1;
Each image in the stack needs to be timed to appear, then disappear as the next image in the stack becomes visible. To do this, use animation-delay and increase it for each image in the stack.
#slider img:nth-child(1) {
animation-delay: 0s;
}
#slider img:nth-child(2) {
animation-delay: 4s;
opacity:0;
}
#slider img:nth-child(3) {
animation-delay: 8s;
opacity:0;
}
#slider img:nth-child(4) {
animation-delay: 12s;
opacity:0;
}
The staggered animation-delay properties cause the first image in the stack to be shown initially. It's animation takes 5 seconds and results in the image disappearing. At 4 seconds, the 2nd image in the stack starts it's animation, appearing just as the first image is disappearing. And then so on for the 3rd and 4th images.
In the code above there's also an initial opacity property for the 2nd, 3rd and 4th images. This is necessary to hide them initially.
As it's setup now the images will loop only once. Some minor tweaking to animation-delay and animation-iteration-count would cause it to loop infinitely.
Here's the working demo.

fade-in Styles CSS not working properly in Internet Explorer

My Code for showing divs with fade-in effect is as here
#-webkit-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
#-moz-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
#keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.fade-in {
opacity:0;
-webkit-animation:fadeIn ease-in 1;
-moz-animation:fadeIn ease-in 1;
animation:fadeIn ease-in 1;
-webkit-animation-fill-mode:forwards;
-moz-animation-fill-mode:forwards;
animation-fill-mode:forwards;
-webkit-animation-duration:2s;
-moz-animation-duration:2s;
animation-duration:2s;
}
.fade-in.one
{
-webkit-animation-delay: 1.7s;
-moz-animation-delay: 1.7s;
animation-delay: 1.7s;
}
Then i am using that to a div which needs to fade in while loading.
<div class="fade-in one">
<label>Message Box</label>
This box will show some messages
</div>
This code works fine in chrome and firefox as well, but in ie it is showing no animation.
Kindly help in fixing this problem. I have tried many changes in the code, and IE versions as well. But no joy. Please help ....

Using HTML5 and CSS3 to switch 'frames' ever so many seconds like Flash

I'm wanting to use HTML5 and CSS3 to load an MP3/OGG, and it will read along with text that's being displayed. As it finishes what's on the screen, it switches to a new screen.
So the first screen would load when the mp3 starts, and stay until 12 seconds(that's how long it takes the voice on the mp3 to read it). At 12 seconds, it switches to the next text, which will stay until 22 seconds. There will be 7 paragraphs in total.
Below is some coding I found of an example, but I can't edit it to work properly with the timing I need.
Basics of the HTML:
<audio controls="controls" preload="auto" autoplay="autoplay">
<source src="valmp3.ogg" type="audio/ogg" />
<source src="valmp3.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
<ul>
<li>Paragraph 1</li>
<!--^^Should load when the mp3 starts and stay for 12 seconds^^-->
<li>Paragraph 2</li>
<!--^^Should load at 12 seconds and stay until 22 seconds^^-->
<li> Paragraph 3</li>
<li> Paragraph 4</li>
<li>Paragraph 5</li>
<li>Paragraph 6</li>
<li>Paragraph 7</li>
</ul>
The CSS:
* {
margin: 0;
padding: 0;
}
body{
background: #422A20;
font-size: 2em;
}
ul {
height: 100%;
left: 0;
position: fixed;
top: 0;
width: 100%;
z-index: 0;
}
ul li {
color: transparent;
font-size: 250%;
position: absolute;
text-align: center;
top: 35%;
width: 100%;
}
/* delay between each text */
ul li:nth-child(1),
ul li:nth-child(2),
ul li:nth-child(3),
ul li:nth-child(4) {
-moz-animation: blurFadeInOut 3s ease-in backwards;
-ms-animation: blurFadeInOut 3s ease-in backwards;
-webkit-animation: blurFadeInOut 3s ease-in backwards;
}
ul li:nth-child(1) {
-webkit-animation-delay: 0s;
-moz-animation-delay: 0s;
-ms-animation-delay: 0s;
animation-delay: 0s;
}
ul li:nth-child(2) {
-webkit-animation-delay: 3s;
-moz-animation-delay: 3s;
-ms-animation-delay: 3s;
animation-delay: 3s;
}
ul li:nth-child(3) {
-webkit-animation-delay: 6s;
-moz-animation-delay: 6s;
-ms-animation-delay: 6s;
animation-delay: 6s;
}
ul li:nth-child(4) {
-webkit-animation-delay: 9s;
-moz-animation-delay: 9s;
-ms-animation-delay: 9s;
animation-delay: 9s;
}
ul li:nth-child(5) {
-webkit-animation-delay: 12s;
-moz-animation-delay: 12s;
-ms-animation-delay: 12s;
animation-delay: 12s;
}
/* delay for the last slide */
ul li:nth-child(5) span {
-webkit-animation: blurFadeIn 3s ease-in 12s backwards;
-moz-animation: blurFadeIn 1s ease-in 12s backwards;
-ms-animation: blurFadeIn 3s ease-in 12s backwards;
animation: blurFadeIn 3s ease-in 12s backwards;
color: transparent;
text-shadow: 0px 0px 1px #fff;
}
ul li:nth-child(5) span:nth-child(2) {
-webkit-animation-delay: 13s;
-moz-animation-delay: 13s;
-ms-animation-delay: 13s;
animation-delay: 13s;
}
ul li:nth-child(5) span:nth-child(3) {
-webkit-animation-delay: 14s;
-moz-animation-delay: 14s;
-ms-animation-delay: 14s;
animation-delay: 14s;
}
Code for the animation:
#-moz-keyframes blurFadeInOut {
0% { opacity: 0; text-shadow: 0px 0px 40px #fff; -moz-transform: scale(1.3); }
25%, 75% { opacity: 1; text-shadow: 0px 0px 1px #fff; -moz-transform: scale(1); }
100% { opacity: 0; text-shadow: 0px 0px 50px #fff; -moz-transform: scale(0); }
}
#-webkit-keyframes blurFadeInOut {
0% { opacity: 0; text-shadow: 0px 0px 40px #fff; -webkit-transform: scale(1.3); }
25%, 75% { opacity: 1; text-shadow: 0px 0px 1px #fff; -webkit-transform: scale(1); }
100% { opacity: 0; text-shadow: 0px 0px 50px #fff; -webkit-transform: scale(0); }
}
#keyframes blurFadeInOut {
0% { opacity: 0; text-shadow: 0px 0px 40px #fff; transform: scale(1.3); }
25%, 75% { opacity: 1; text-shadow: 0px 0px 1px #fff; transform: scale(1); }
100% { opacity: 0; text-shadow: 0px 0px 50px #fff; transform: scale(0); }
}
I think you're wanting something like this: http://jsfiddle.net/VL3Ub/ (with perhaps different effects)
I reduced it to the simplest form I could.
<ul>
<li>Hello (hello hello hello)</li>
<li>Is there anybody in there?</li>
<li>Just nod if you can hear me.</li>
</ul>​
CSS
#-webkit-keyframes fadeInOut{
from,to{opacity:0;}
25%,75%{opacity:1;}
}
ul li{
opacity:0;
-webkit-animation: fadeInOut 4s ease-in;
}
ul li:nth-child(2){
-webkit-animation-delay:4s;
}
ul li:nth-child(3){
-webkit-animation-delay:8s;
}
So, each li will fade in for 1 second, be visible for 2 seconds, then fade out for 1 second. I then simply stagger the animations by setting the delay >= the animation time.
Managing everything might become a little more tricky when accounting for nested animations, but it should follow the same principle.
I'm not sure if this answers your question, or points you in the right direction, so let me know if it doesn't. :)
You can do this to make the animation last longer. I would suggest adjusting the blurFadeInOut visible steps to 10%,90%, or adding a second version of the animation for the longer duration.
ul li:nth-child(1) {
-webkit-animation-duration:12s;
-webkit-animation-delay: 0s;
}
ul li:nth-child(2) {
-webkit-animation-duration:10s;
-webkit-animation-delay: 12s;
}
ul li:nth-child(3) {
-webkit-animation-delay: 22s;
}
ul li:nth-child(4) {
-webkit-animation-delay: 25s;
}