CSS3 Animation - Smooth Infinite Animation - html

I've made a small Image animation where images changes opacity over time.It works smoothly but when last image gets to 100% it jumps straight to 0% without any transition.
I have already tried animation-direction: alternate for third image and delay for all image but it does not work for me. Delay works only first step of animation cycle after it delay becomes 0 for all.
Here is my CSS
.rightside .img-container img.first {
animation-name: first-image;
animation-duration: 9s;
animation-fill-mode: both;
animation-iteration-count: infinite;
/* animation-delay: -10s; */
}
.rightside .img-container img.second {
position: absolute;
top: 0;
animation-name: second-image;
animation-duration: 9s;
animation-fill-mode: both;
animation-iteration-count: infinite;
}
.rightside .img-container img.third {
position: absolute;
top: 0;
animation-name: final-image;
animation-duration: 9s;
animation-fill-mode: both;
animation-iteration-count: infinite;
animation-timing-function: linear;
/* animation-direction: alternate; */
}
#keyframes first-image {
0% {
opacity: 0;
}
33.3% {
opacity: 1;
}
67% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#keyframes second-image {
0% {
opacity: 0;
}
33.3% {
opacity: 0;
}
67% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#keyframes final-image {
0% {
opacity: 0;
}
33.3% {
opacity: 0;
}
67% {
opacity: 0;
}
100% {
opacity: 1;
}
}
HTML
<div class="img-container">
<img src="Images/Apple.png" class="first turn" alt="Image Here" />
<img src="Images/Bee.png" class="second" alt="Image Here" />
<img src="Images/Cat.png" class="third" alt="Image Here" />
</div>

The clasical aproach to this would be just using different delays:
div {
animation-name: all;
animation-duration: 9s;
animation-iteration-count: infinite;
width: 100px;
height: 100px;
background-color: yellow;
}
.first {
animation-delay: -3s;
background-color: lightgreen;
}
.third {
animation-delay: -6s;
background-color: lightblue;
}
#keyframes all {
0% {
opacity: 0;
}
33.3% {
opacity: 1;
}
67% {
opacity: 0;
}
100% {
opacity: 0;
}
}
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>

Related

How to hide image after animation using css?

I tried the following code To Fade Out The Image ,
.splash-wrapper {
animation: fadeIn 4s;
-webkit-animation: fadeIn 4s;
-moz-animation: fadeIn 4s;
-o-animation: fadeIn 4s;
-ms-animation: fadeIn 4s;
animation-duration: 3s;
animation-delay: 3.1s;
}
#keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-moz-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-webkit-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-o-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-ms-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
.splash-wrapper {
position: fixed;
z-index: 9999;
background-color: #86FF0000;
height: 100vh;
width: 100vw;
display: flex;
flex-flow: column nowrap
justify-content: center;
align-items: center;
animation-duration: 3s;
animation-delay: 3.1s;
}
#keyframes slideOut {
from{margin-left: 0vw;}
to{margin-left: -150vw;}
}
<div class="splash-wrapper">
<img src="https://picsum.photos/200">
</div>
It fades out the image but it's reappearing again and even never fades or becomes invicible. How can i hide the image completely after the animation? .
Should i also mention it's visibility?
Check animation-fill-mode property
.splash-wrapper {
animation-fill-mode: forwards;
}
Try this!
.splash-wrapper {
animation: fadeIn 4s;
-webkit-animation: fadeIn 4s;
-moz-animation: fadeIn 4s;
-o-animation: fadeIn 4s;
-ms-animation: fadeIn 4s;
position: fixed;
z-index: 9999;
background-color: #86FF0000;
height: 100vh;
width: 100vw;
display: flex;
flex-flow: column nowrap
justify-content: center;
align-items: center;
animation-duration: 3s;
animation-delay: 3.1s;
animation-fill-mode: forwards;
}
#keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-moz-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-webkit-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-o-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-ms-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#keyframes slideOut {
from{margin-left: 0vw;}
to{margin-left: -150vw;}
}
<div class="splash-wrapper">
<img src="https://picsum.photos/200">
</div>
Thanks and best regards!
You can solve this with animation-fill-mode: forwards or you add it directly to your animation call:
animation: fadeIn 4s forwards;
Working example:
(I removed the unused #keyframes slideOut, the double CSS-code and the animation-duration, because you defined the duration already directly in the animation call)
.splash-wrapper {
position: fixed;
z-index: 9999;
background-color: #86FF0000;
height: 100vh;
width: 100vw;
display: flex;
flex-flow: column nowrap
justify-content: center;
align-items: center;
animation: fadeIn 4s forwards;
-webkit-animation: fadeIn 4s forwards;
-moz-animation: fadeIn 4s forwards;
-o-animation: fadeIn 4s forwards;
-ms-animation: fadeIn 4s forwards;
animation-delay: 3.1s;
}
#keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-moz-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-webkit-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-o-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
#-ms-keyframes fadeIn {
0% { opacity: 1; }
100% { opacity: 0; }
}
<div class="splash-wrapper">
<img src="https://picsum.photos/200">
</div>
If you want to disappear the .splash-wrapper instead of just getting invisible, you can animate the height too:
#keyframes fadeIn {
0% { opacity: 1; height: 100vh; }
75% { opacity: 0; height: 100vh; }
100% { opacity: 0; height: 0vh; }
}
(75% ist just an example - you could also take 99% o.s.)
Working example:
.splash-wrapper {
position: fixed;
z-index: 9999;
background-color: #86FF0000;
height: 100vh;
width: 100vw;
display: flex;
flex-flow: column nowrap
justify-content: center;
align-items: center;
animation: fadeIn 4s forwards;
-webkit-animation: fadeIn 4s forwards;
-moz-animation: fadeIn 4s forwards;
-o-animation: fadeIn 4s forwards;
-ms-animation: fadeIn 4s forwards;
animation-delay: 3.1s;
}
#keyframes fadeIn {
0% { opacity: 1; height: 100vh; }
75% { opacity: 0; height: 100vh; }
100% { opacity: 0; height: 0; }
}
#-moz-keyframes fadeIn {
0% { opacity: 1; height: 100vh; }
75% { opacity: 0; height: 100vh; }
100% { opacity: 0; height: 0; }
}
#-webkit-keyframes fadeIn {
0% { opacity: 1; height: 100vh; }
75% { opacity: 0; height: 100vh; }
100% { opacity: 0; height: 0; }
}
#-o-keyframes fadeIn {
0% { opacity: 1; height: 100vh; }
75% { opacity: 0; height: 100vh; }
100% { opacity: 0; height: 0; }
}
#-ms-keyframes fadeIn {
0% { opacity: 1; height: 100vh; }
75% { opacity: 0; height: 100vh; }
100% { opacity: 0; height: 0; }
}
<div class="splash-wrapper">
<img src="https://picsum.photos/200">
</div>
If manipulating the height is still not enough and you really want to hide the element after the animation, you have to use Javascript. You could use the animate() function, the setTimeout() function for the delay and a promise ( then() ) for setting the display property:
setTimeout(function() {
splash_wrapper.animate(key_frames, timing_options).finished.then(function() {
splash_wrapper.style.display = 'none';
});
}, 3100);
Working example:
const splash_wrapper = document.querySelector(".splash-wrapper");
const key_frames = [
{ opacity: '1'},
{ opacity: '0'}
];
const timing_options = {
duration: 4000,
iterations: 1,
}
setTimeout(function() {
splash_wrapper.animate(key_frames, timing_options).finished.then(function() {
splash_wrapper.style.display = 'none';
});
}, 3100);
.splash-wrapper {
position: fixed;
z-index: 9999;
background-color: #86FF0000;
height: 100vh;
width: 100vw;
display: flex;
flex-flow: column nowrap
justify-content: center;
align-items: center;
}
<div class="splash-wrapper">
<img src="https://picsum.photos/200">
</div>

I am trying to create 3 columns with responsive fade rendering. How do I get them to display next to each other rather than on top of each other?

How do I get the three columns to display next to each other rather than on top of each other? Of course I also want them to be responsive and fade.
My fiddle: https://jsfiddle.net/Spleendrivel/dswufb78/3/
<!DOCTYPE html>
<html>
<head>
<meta name="ac:base" content="/AlmostYou">
<base href="/AlmostYou/">
<style>
/* Slider */
/* Slideshow container */
#slide-container-1 {
position: relative;
max-width: 100%;
/* responsiveness */
}
/* Slider */
/* Slideshow container */
#slide-container-2 {
position: relative;
max-width: 100%;
/* responsiveness */
}
/* Slider */
/* Slideshow container */
#slide-container-3 {
position: relative;
max-width: 100%;
/* responsiveness */
}
/* First element to be in block mode for responsiveness */
#slide-element-1 {
display: block;
/* to get the dimensions set */
width: 100%;
height: auto;
}
/* First element to be in block mode for responsiveness */
#slide-element-4 {
display: block;
/* to get the dimensions set */
width: 100%;
height: auto;
}
/* First element to be in block mode for responsiveness */
#slide-element-7 {
display: block;
/* to get the dimensions set */
width: 100%;
height: auto;
}
/* Other element to be in absolute position */
#slide-element-2,
#slide-element-3,
#slide-element-5,
#slide-element-6,
#slide-element-8,
#slide-element-9 {
position: absolute;
width: 100%;
height: 100%;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
/* Style images */
.slide-image {
width: 100%;
border-radius: 20px;
}
/* Style text */
.slide-text {
position: absolute;
bottom: 10px;
background-color: #0042b1bb;
color: white;
width: 100%;
text-align: center;
font-size: 1.5rem;
}
/* Animation settings for individual elements */
/* For more images the animations have to be adjusted */
#slide-element-1 {
animation: fade-1 10s infinite;
-webkit-animation: fade-1 10s infinite;
}
#slide-element-2 {
animation: fade-2 10s infinite;
-webkit-animation: fade-2 10s infinite;
}
#slide-element-3 {
animation: fade-3 10s infinite;
-webkit-animation: fade-3 10s infinite;
}
#slide-element-4 {
animation: fade-4 10s infinite;
-webkit-animation: fade-4 10s infinite;
}
#slide-element-5 {
animation: fade-5 10s infinite;
-webkit-animation: fade-5 10s infinite;
}
#slide-element-6 {
animation: fade-6 10s infinite;
-webkit-animation: fade-6 10s infinite;
}
#slide-element-7 {
animation: fade-7 10s infinite;
-webkit-animation: fade-7 10s infinite;
}
#slide-element-8 {
animation: fade-8 10s infinite;
-webkit-animation: fade-8 10s infinite;
}
#slide-element-9 {
animation: fade-9 10s infinite;
-webkit-animation: fade-9 10s infinite;
}
/* and more if there are more slides to show */
#keyframes fade-1 {
0% {
opacity: 1;
}
33% {
opacity: 0;
}
66% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fade-2 {
0% {
opacity: 0;
}
33% {
opacity: 1;
}
66% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#keyframes fade-3 {
0% {
opacity: 0;
}
33% {
opacity: 0;
}
66% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#keyframes fade-4 {
0% {
opacity: 1;
}
33% {
opacity: 0;
}
66% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fade-5 {
0% {
opacity: 0;
}
33% {
opacity: 1;
}
66% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#keyframes fade-6 {
0% {
opacity: 0;
}
33% {
opacity: 0;
}
66% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#keyframes fade-7 {
0% {
opacity: 1;
}
33% {
opacity: 0;
}
66% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fade-8 {
0% {
opacity: 0;
}
33% {
opacity: 1;
}
66% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#keyframes fade-9 {
0% {
opacity: 0;
}
33% {
opacity: 0;
}
66% {
opacity: 1;
}
100% {
opacity: 0;
}
}
</style>
</head>
<body>
<div class="row">
<div class="column">
<div id="slide-container-1">
<div id="slide-element-1">
<img class="slide-image" src="barn-3.jpg">
</div>
<div id="slide-element-2">
<img class="slide-image" src="barn-2.jpg">
</div>
<div id="slide-element-3">
<img class="slide-image" src="barn-1.jpg">
</div>
</div>
</div>
<div class="column">
<div id="slide-container-2">
<div id="slide-element-4">
<img class="slide-image" src="cat-1.jpg">
</div>
<div id="slide-element-5">
<img class="slide-image" src="cat-2.jpg">
</div>
<div id="slide-element-6">
<img class="slide-image" src="cat-3.jpg">
</div>
</div>
</div>
<div class="column">
<div id="slide-container-3">
<div id="slide-element-7">
<img class="slide-image" src="dog-2.jpg">
</div>
<div id="slide-element-8">
<img class="slide-image" src="dog-1.jpg">
</div>
<div id="slide-element-9">
<img class="slide-image" src="dog-3.jpg">
</div>
</div>
</div>
</div>
</body>
</html>
Make sure the screen width is no more than 350 to see my problem.
I am adding additional lines of text over and over because I can not submit my question without more text content. I am adding additional lines of text over and over because I can not submit my question without more text content. I am adding additional lines of text over and over because I can not submit my question without more text content. I am adding additional lines of text over and over because I can not submit my question without more text content. I am adding additional lines of text over and over because I can not submit my question without more text content.
I guess you have to use css grid or flexbox;
but css grid is the best choice here:
.row {
display: grid;
grid-templates-rows: auto; // you can add columns as many as you want..
grid-templates-columns: repeat(3, 1fr); //.. but you will get 3 columns for each row
}
if didn't work then you have to make some changes in your css.
I think you can try using flexbox (flex-direction: row)
Here is the final answer:
my JSFiddle: https://jsfiddle.net/Spleendrivel/mcyvpx3r/2/
<!DOCTYPE html>
<html>
<head>
<meta name="ac:base" content="/AlmostYou">
<base href="/AlmostYou/">
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
}
.header {
text-align: center;
padding: 32px;
}
.row {
display: -ms-flexbox;
/* IE10 */
display: flex;
-ms-flex-wrap: wrap;
/* IE10 */
flex-wrap: wrap;
padding: 0 4px;
}
/* Create four equal columns that sits next to each other */
.column {
-ms-flex: 33%;
/* IE10 */
flex: 33%;
max-width: 33%;
padding: 0 4px;
}
.column img {
margin-top: 8px;
vertical-align: middle;
width: 100%;
}
.fadein-1 img {
position: absolute;
top: 0;
-webkit-animation-name: fade;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 6s;
animation-name: fade;
animation-iteration-count: infinite;
animation-duration: 6s;
-ms-flex: 33%;
/* IE10 */
flex: 33%;
max-width: 33%;
padding: 0 4px;
}
.fadein-2 img {
position: absolute;
top: 0;
-webkit-animation-name: fade;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 6s;
animation-name: fade;
animation-iteration-count: infinite;
animation-duration: 6s;
-ms-flex: 33%;
/* IE10 */
flex: 33%;
max-width: 33%;
padding: 0 4px;
}
.fadein-3 img {
position: absolute;
top: 0;
-webkit-animation-name: fade;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 6s;
animation-name: fade;
animation-iteration-count: infinite;
animation-duration: 6s;
-ms-flex: 33%;
/* IE10 */
flex: 33%;
max-width: 33%;
padding: 0 4px;
}
#-webkit-keyframes fade {
0% {
opacity: 0;
}
20% {
opacity: 1;
}
33% {
opacity: 1;
}
53% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#keyframes fade {
0% {
opacity: 0;
}
20% {
opacity: 1;
}
33% {
opacity: 1;
}
53% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#f2 {
-webkit-animation-delay: -4s;
}
#f3 {
-webkit-animation-delay: -2s;
}
#f5 {
-webkit-animation-delay: -4s;
}
#f6 {
-webkit-animation-delay: -2s;
}
#f8 {
-webkit-animation-delay: -4s;
}
#f9 {
-webkit-animation-delay: -2s;
}
</style>
</head>
<body>
<div class="row">
<div class="column">
<div class="fadein-1">
<img id="f3" src="http://snaklvr.com/barn-3.jpg">
<img id="f2" src="http://snaklvr.com/barn-2.jpg">
<img src="http://snaklvr.com/barn-1.jpg">
</div>
</div>
<div class="column">
<div class="fadein-2">
<img src="http://snaklvr.com/cat-3.jpg">
<img id="f5" src="http://snaklvr.com/cat-2.jpg">
<img id="f6" src="http://snaklvr.com/cat-1.jpg">
</div>
</div>
<div class="column">
<div class="fadein-3">
<img src="http://snaklvr.com/dog-3.jpg">
<img id="f8" src="http://snaklvr.com/dog-2.jpg">
<img id="f9" src="http://snaklvr.com/dog-1.jpg">
</div>
</div>
</div>
</body>
</html>
I am sure there is some unnecessary CSS or possibly redundancy, but it works as I need!
Flex is your best friend when it comes to arranging elements in a grid and not using a framework such as bootstrap. Here's a great resource for you: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Also, if any of the answers fixed your issue, please mark it as accepted.

hide a text at the end of the animation

.title2 {
position: absolute;
top: 0;
right: 31%;
animation-name: fadeOutOpacity;
animation-iteration-count: 1;
animation-delay: 2.5s;
animation-timing-function: ease-out;
animation-duration: 1s;
}
#keyframes fadeOutOpacity {
0% {
opacity: 1;
}
90% {
opacity: 0;
}
100% {
display: none;
}
}
Could someone explain to me how I can make it disappear? I thought so it worked but it doesn't work! I wanted to make a text disappear, the effect works but then the text comes back visible when instead I would like to hide it permanently at the end of the animation.
You can use the CSS property animation-fill-mode, and change your Keyframe Animation like so:
.title2 {
position: absolute;
top: 0;
right: 31%;
animation-name: fadeOutOpacity;
animation-iteration-count: 1;
animation-delay: 2.5s;
animation-timing-function: ease-out;
animation-duration: 1s;
animation-fill-mode: forwards;
}
#keyframes fadeOutOpacity {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
If you even toggle the display property from none to block, your transition on other elements will not occur. It's work only with displayed elements. If u want to hide element u can use opacity, height
.title2 {
width: 100px;
height: 50px;
background: red;
position: absolute;
top: 0;
right: 31%;
animation: 1s fadeOutOpacity ease-out;
opacity: 0
}
#keyframes fadeOutOpacity {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
<div class="title2"/>

CSS fading animation delay timing

I'm trying to create a slideshow effect with css3 I have three images which I need to fade into each one another. - each transition needs to last for 3 seconds.
1st image shows for 3seconds then fades to 2nd and same to third
I'm unsure how to work out the percentage for the keyframes.
Codepen http://codepen.io/anon/pen/MYmPYp
#-webkit-keyframes cf4FadeInOut {
0% {
opacity: 1;
}
17% {
opacity: 1;
}
25% {
opacity: 1;
}
92% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#-moz-keyframes cf4FadeInOut {
0% {
opacity: 1;
}
17% {
opacity: 1;
}
25% {
opacity: 1;
}
92% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#-ms-keyframes cf4FadeInOut {
0% {
opacity: 1;
}
17% {
opacity: 1;
}
25% {
opacity: 1;
}
92% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes cf4FadeInOut {
0% {
opacity: 1;
}
17% {
opacity: 1;
}
25% {
opacity: 1;
}
92% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.team-img {
position: relative;
height: 329px;
width: 450px;
}
.team-img img {
position: absolute;
left: 0;
z-index: 0;
-webkit-animation-name: cf4FadeInOut;
-moz-animation-name: cf4FadeInOut;
-ms-animation-name: cf4FadeInOut;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-timing-function: ease-in-out;
animation-timing-function: ease-in-out;
-webkit-animation-duration: 9s;
-moz-animation-duration: 9s;
-ms-animation-duration: 9s;
}
.team-img img:nth-of-type(1) {
-webkit-animation-name: cf4FadeInOut;
-moz-animation-name: cf4FadeInOut;
-ms-animation-name: cf4FadeInOut;
-webkit-animation-delay: 3s;
-moz-animation-delay: 3s;
-ms-animation-delay: 3s;
}
.team-img img:nth-of-type(2) {
-webkit-animation-name: cf4FadeInOut;
-moz-animation-name: cf4FadeInOut;
-ms-animation-name: cf4FadeInOut;
-webkit-animation-delay: 6s;
-moz-animation-delay: 6s;
-ms-animation-delay: 6s;
}
.team-img img:nth-of-type(3) {
-webkit-animation-name: cf4FadeInOut;
-moz-animation-name: cf4FadeInOut;
-ms-animation-name: cf4FadeInOut;
-webkit-animation-delay: 9s;
-moz-animation-delay: 9s;
-ms-animation-delay: 9s;
}
<div class="team-img">
<img width="200px" height="200px" src="http://blackdogballroom.co.uk/nws/wp-content/uploads/sites/2/2014/11/BDB-290212-Img-048.jpg">
<img width="200px" height="200px" src="http://3.bp.blogspot.com/-I2TYXJ3lDYw/UFsjvkedaXI/AAAAAAAAE-w/7EYzTeZMpsc/s1600/00Halloween+Spooks.JPG">
<img width="200px" height="200px" src="http://blog.lafraise.com/fr/wp-content/uploads/2013/11/Free-hug-zoneinfinite.jpg">
</div>
I've been racking my brain for a few hours, slowly losing the will. I've googled effortlessly.
Thanks,
Dan
You need to define three different #keyframes to achieve this.
#-webkit-keyframes two {
0% { opacity: 0; }
8.3% { opacity: 0; }
16.6% { opacity: 0; }
24.9% { opacity: 0; }
33.2% { opacity: 1; }
41.5% { opacity: 1; }
49.5% { opacity: 1; }
58.1% { opacity: 1; }
66.4% { opacity: 0; }
74.7% { opacity: 0; }
83% { opacity: 0; }
91.3% { opacity: 0; }
100% { opacity: 0; }
}
#keyframes two {
0% { opacity: 0; }
8.3% { opacity: 0; }
16.6% { opacity: 0; }
24.9% { opacity: 0; }
33.2% { opacity: 1; }
41.5% { opacity: 1; }
49.5% { opacity: 1; }
58.1% { opacity: 1; }
66.4% { opacity: 0; }
74.7% { opacity: 0; }
83% { opacity: 0; }
91.3% { opacity: 0; }
100% { opacity: 0; }
}
#-webkit-keyframes three {
0% { opacity: 0; }
8.3% { opacity: 0; }
16.6% { opacity: 0; }
24.9% { opacity: 0; }
33.2% { opacity: 0; }
41.5% { opacity: 0; }
49.5% { opacity: 0; }
58.1% { opacity: 0; }
66.4% { opacity: 1; }
74.7% { opacity: 1; }
83% { opacity: 1; }
91.3% { opacity: 1; }
100% { opacity: 0; }
}
#keyframes three {
0% { opacity: 0; }
8.3% { opacity: 0; }
16.6% { opacity: 0; }
24.9% { opacity: 0; }
33.2% { opacity: 0; }
41.5% { opacity: 0; }
49.5% { opacity: 0; }
58.1% { opacity: 0; }
66.4% { opacity: 1; }
74.7% { opacity: 1; }
83% { opacity: 1; }
91.3% { opacity: 1; }
100% { opacity: 0; }
}
.team-img {
position: relative;
height: 329px;
width: 450px;
}
.team-img img {
position: absolute;
left: 0;
z-index: 0;
}
.team-img img:nth-of-type(2) {
-webkit-animation: two 11s ease-in-out infinite forwards;
animation: two 11s ease-in-out infinite forwards;
}
.team-img img:nth-of-type(3) {
-webkit-animation: three 11s ease-in-out infinite forwards;
animation: three 11s ease-in-out infinite forwards;
}
<div class="team-img">
<img width="200px" height="200px" src="http://blackdogballroom.co.uk/nws/wp-content/uploads/sites/2/2014/11/BDB-290212-Img-048.jpg">
<img width="200px" height="200px" src="http://3.bp.blogspot.com/-I2TYXJ3lDYw/UFsjvkedaXI/AAAAAAAAE-w/7EYzTeZMpsc/s1600/00Halloween+Spooks.JPG">
<img width="200px" height="200px" src="http://blog.lafraise.com/fr/wp-content/uploads/2013/11/Free-hug-zoneinfinite.jpg">
</div>
You don't need to animate the first image, only the second and third. It makes a code much shorter:
.team-img {
position: relative;
height: 329px;
width: 450px;
}
.team-img img {
position: absolute;
left: 0;
top: 0;
}
.team-img img:nth-of-type(2) {
opacity: 0;
-webkit-animation: fading2 ease 14s infinite;
animation: fading2 ease 14s infinite;
}
.team-img img:nth-of-type(3) {
opacity: 0;
-webkit-animation: fading3 ease 14s infinite;
animation: fading3 ease 14s infinite;
}
#-webkit-keyframes fading2 {
0%: { opacity: 0;}
21% { opacity: 0;}
35% { opacity: 1;}
93% { opacity: 1;}
100% { opacity: 0;}
}
#keyframes fading2 {
0%: { opacity: 0;}
21% { opacity: 0;}
35% { opacity: 1;}
93% { opacity: 1;}
100% { opacity: 0;}
}
#-webkit-keyframes fading3 {
0%: { opacity: 0;}
56% { opacity: 0;}
70% { opacity: 1;}
93% { opacity: 1;}
100% { opacity: 0;}
}
#keyframes fading3 {
0%: { opacity: 0;}
56% { opacity: 0;}
70% { opacity: 1;}
93% { opacity: 1;}
100% { opacity: 0;}
}
<div class="team-img">
<img width="200px" height="200px" src="http://blackdogballroom.co.uk/nws/wp-content/uploads/sites/2/2014/11/BDB-290212-Img-048.jpg">
<img width="200px" height="200px" src="http://3.bp.blogspot.com/-I2TYXJ3lDYw/UFsjvkedaXI/AAAAAAAAE-w/7EYzTeZMpsc/s1600/00Halloween+Spooks.JPG">
<img width="200px" height="200px" src="http://blog.lafraise.com/fr/wp-content/uploads/2013/11/Free-hug-zoneinfinite.jpg">
</div>

Crossfade two images repeatedly after showing for 10 seconds

I'm trying to use HTML and CSS to crossfade two images after showing them for 10 seconds each. I want this to repeat constantly.
Here is my HTML:
<div id="container">
<img class="bottom" src="1.png">
<img class="top" src="2.png">
</div>
CSS:
#container {
float: right;
height: 246px;
position:relative;
width: 230px;
}
#container img {
height: 246px;
width: 230px;
left:0;
opacity: 0;
position:absolute;
}
#container img.bottom {
opacity: 1;
}
#container img.top {
animation-duration: 0.1s;
animation-name: crossFade;
animation-iteration-count: infinite;
animation-direction: alternate;
}
#keyframes crossFade {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
I've never used CSS animations before so I'm a bit confused. Only the "bottom" image is being shown and nothing else happens.
What is going wrong?
Here is an example with 10s delay and 1s animation duration.
#container {
float: right;
height: 246px;
position: relative;
width: 230px;
}
#container img {
height: 246px;
width: 230px;
left: 0;
opacity: 0;
position: absolute;
}
#container img.bottom {
opacity: 1;
}
#container img.top {
-webkit-animation: crossFade 11s infinite;
animation: crossFade 11s infinite;
-webkit-animation-direction: alternate;
animation-direction: alternate;
}
#-webkit-keyframes crossFade {
0% {
opacity: 0;
}
47.62% {
opacity: 0;
}
52.38% {
opacity: 1;
}
100% {
opacity: 1;
}
}
#keyframes crossFade {
0% {
opacity: 0;
}
47.62% {
opacity: 0;
}
52.38% {
opacity: 1;
}
100% {
opacity: 1;
}
}
<div id="container">
<img class="bottom" src="https://dummyimage.com/200x200/404/fff">
<img class="top" src="https://dummyimage.com/200x200/101/fff">
</div>