Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

CSS Animation using multiple background images

Hello all!

I'm trying to create an animation using 14 background images that go one after another. Without any of them interfering with each other so far here's my code:

``<div id="crossfade"> <img src="http://www.nousacademy.com/img/daytonight-1.jpg" alt="Image 1"> <img src="http://www.nousacademy.com/img/daytonight-2.jpg" alt="Image 2"> <img src="http://www.nousacademy.com/img/daytonight-3.jpg" alt="Image 3"> <img src="http://www.nousacademy.com/img/daytonight-4.jpg" alt="Image 4"> <img src="http://www.nousacademy.com/img/daytonight-5jpg" alt="Image 5"> <img src="http://www.nousacademy.com/img/daytonight-6.jpg" alt="Image 6"> <img src="http://www.nousacademy.com/img/daytonight-7.jpg" alt="Image 7"> <img src="http://www.nousacademy.com/img/daytonight-8.jpg" alt="Image 8"> <img src="http://www.nousacademy.com/img/daytonight-9.jpg" alt="Image 9"> <img src="http://www.nousacademy.com/img/daytonight-10.jpg" alt="Image 10"> <img src="http://www.nousacademy.com/img/daytonight-11.jpg" alt="Image 11"> <img src="http://www.nousacademy.com/img/daytonight-12.jpg" alt="Image 12"> <img src="http://www.nousacademy.com/img/daytonight-13.jpg" alt="Image 13"> <img src="http://www.nousacademy.com/img/daytonight-14.jpg" alt="Image 14"> </div>

'''#crossfade > img { 
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0px;
    left: 0px;
    color: transparent;
    opacity: 0;
    z-index: 0;
    -webkit-backface-visibility: hidden;
    -webkit-animation: imageAnimation 6s linear infinite 0s;
    -moz-animation: imageAnimation 6s linear infinite 0s;
    -o-animation: imageAnimation 6s linear infinite 0s;
    -ms-animation: imageAnimation 6s linear infinite 0s;
    animation: imageAnimation 6s linear infinite 0s; 
}

#crossfade > img:nth-child(2)  {
    -webkit-animation-delay: 6s;
    -moz-animation-delay: 6s;
    -o-animation-delay: 6s;
    -ms-animation-delay: 6s;
    animation-delay: 6s; 
}
#crossfade > img:nth-child(3) {
    -webkit-animation-delay: 12s;
    -moz-animation-delay: 12s;
    -o-animation-delay: 12s;
    -ms-animation-delay: 12s;
    animation-delay: 12s; 
}
#crossfade > img:nth-child(4) {
    -webkit-animation-delay: 18s;
    -moz-animation-delay: 18s;
    -o-animation-delay: 18s;
    -ms-animation-delay: 18s;
    animation-delay: 18s; 
}
#crossfade > img:nth-child(5) {
    -webkit-animation-delay: 24s;
    -moz-animation-delay: 24s;
    -o-animation-delay: 24s;
    -ms-animation-delay: 24s;
    animation-delay: 24s; 
}

@-webkit-keyframes imageAnimation { 
    0% { opacity: 0;
    -webkit-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -webkit-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}

@-moz-keyframes imageAnimation { 
    0% { opacity: 0;
    -moz-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -moz-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}

@-o-keyframes imageAnimation { 
    0% { opacity: 0;
    -o-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -o-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}

@-ms-keyframes imageAnimation { 
    0% { opacity: 0;
    -ms-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -ms-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}

@keyframes imageAnimation { 
    0% { opacity: 0;
    animation-timing-function: ease-in; }
    8% { opacity: 1;
         animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}'''

never mind I figured it out!