0

I am trying to animate two pictures so that they change at fixed intervals but the problem is that the second image appears quickly and fades I need a way to make the delay property to repeat i have refereed this but that doesn't seem to work CSS animation delay in repeating
http://jsfiddle.net/fc3nb5rL/2/

I think my problem is somewhere here

@-webkit-keyframes anim {
from {
    z-index:1;
}
to {
    z-index:-2;
}
}
.back {
-webkit-animation:anim 5s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-timing-function: ease-in-out;
}

@-webkit-keyframes anim2 {
from {
    z-index:1;
}
to {
    z-index:-2;
}
}
Community
  • 1
  • 1
Akshay
  • 14,138
  • 5
  • 46
  • 70

2 Answers2

1

First fix your HTML(markup), then you can animate the opacity and not the z-index

.container {
    position:relative;
    height:500px;
    width:500px;
    margin:0 auto;
}
.container img {
    position:absolute;
    width:100%;
}

@-webkit-keyframes anim1 {
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}


@-webkit-keyframes anim2 {
    from {
        opacity:1;
    }
    to {
        opacity:0;
    }
}

[href=first] img {
     opacity:0;
     /*animation----:----name--duration--delay--timing function---direction----iteration count*/
     -webkit-animation: anim1 2s 0s linear alternate infinite;
}
[href=second] img {
     opacity:1;
    -webkit-animation: anim2 2s 0s linear alternate infinite;
}
<div class="container">
    <a href="second">
        <img src="http://placekitten.com/300/300" />
    </a>
    <a href="first"> 
        <img class="front" src="http://placekitten.com/300/301" />
    </a>
</div>
Gildas.Tambo
  • 22,173
  • 7
  • 50
  • 78
1
Give this a shot. I have also set it up to be cross-browser compatible. http://jsfiddle.net/fc3nb5rL/2/

A few things to note about CSS3 transitions. It does not know how to interpolate between the z-index     
property, as well as the display property.
Justin Medas
  • 211
  • 1
  • 8
  • sorry about putting all in a code window, stackoverflow told me my fiddle link needed to be indented, so i did that, but wouldn't let me post unless I indented everythin – Justin Medas Sep 25 '14 at 13:39
  • thanks for helping me i've got my answer, using percentage seemed to do the work – Akshay Sep 25 '14 at 13:44