I'm struggling to create a smooth fading effect between two images on my website.
Although the images load in the browser, the animation doesn't seem to be working as expected.
After reviewing my code, I suspect that the issue lies within the @keyframes or #cf3 img.top sections. Interestingly, other sections of the site appear to be functioning correctly. I've tested this on Chrome.
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="cf">
<img class="bottom" src="assets/1.png" />
<img class="top" src="assets/2.png" />
</div>
</body>
</html>
The fading animation is defined in the style.css file:
#cf {
position: relative;
height: 281px;
width: 450px;
margin: 0 auto;
}
#cf img {
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;
}
@keyframes cf3FadeInOut {
0% {
opacity: 1;
}
45% {
opacity: 1;
}
55% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#cf3 img.top {
animation-name: cf3FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 10s;
animation-direction: alternate;
}