链接CSS动画具有无限循环延迟问题

时间:2014-03-09 01:26:02

标签: css css-animations

我在一个循环中链接了两个动画。经过大量调整后,图像无需重叠就可以滚动进出。问题是,一旦动画完成,重启前会有3-4秒的延迟。我没有在我的代码中设置任何延迟,所以认为关键帧存在问题,但是当我玩这些值时,图像开始重叠。

我在这里画了一支笔。目前只有chrome关键帧,动画在codepen中错开,但在chrome中显示正常:

http://codepen.io/Nullbreaker/pen/gnkbq

<div class="rightleftloop">
<img src="http://myshoedream.com/dzinehub/Shoefever/LL10173A-BLACK-4.jpg" class="imgformat1" alt="slide" />
</div>

<div class="rightleftloop2">
<img src="http://myshoedream.com/dzinehub/Shoefever/LL10173BJ-IVORY-4.jpg" class="imgformat1" alt="slide" />
</div>

.rightleftloop {
position: absolute;
-webkit-animation:rightleftloop;
-webkit-animation-duration: 8.5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-fill-mode: both;
-moz-animation:rightleftloop;
-moz-animation-duration: 3.5s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: ease-in 0.3s;
-moz-animation-fill-mode: both;
animation:rightleftloop;
animation-duration: 3.5s;
animation-iteration-count: infinite;
animation-timing-function: ease-in 0.3s;
animation-fill-mode: both;
}

.rightleftloop2 {
position: absolute;
-webkit-animation:rightleftloop2;
-webkit-animation-duration: 8.5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-fill-mode: both;
-moz-animation:rightleftloop;
-moz-animation-duration: 3.5s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: ease-in 0.3s;
-moz-animation-fill-mode: both;
animation:rightleftloop;
animation-duration: 3.5s;
animation-iteration-count: infinite;
animation-timing-function: ease-in 0.3s;
animation-fill-mode: both;
}

@-webkit-keyframes rightleftloop {
0% {right:0%;-webkit-transform: translateX(-2000px);}
10% {right:20%;}
20% {right:20%;}
30% {right:20%;-webkit-transform: translateX(-10px);}
40% {right:20%;-webkit-transform: translateX(-10px);}
60% {right:20%;-webkit-transform: translateX(-2000px);}
100% {right:100%;}
}

@-webkit-keyframes rightleftloop2 {
60% {right:0%;-webkit-transform: translateX(-2000px);}
61%  {right:20%;}
63%  {right:20%;}
64%  {right:20%;}
65% {right:20%;}
65% {right:20%;}
66% {right:20%;}
67% {right:20%;}
68% {right:20%;-webkit-transform: translateX(-2000px);}
69% {right:20%;-webkit-transform: translateX(-1000px);}
}

1 个答案:

答案 0 :(得分:1)

您的动画关键帧不对。我也简化了你的CSS。您可以将此css粘贴到笔中,并亲自查看结果。

body {
    background:#ffffff;
    font-family:'Economica', Arial, sans-serif;
    font-size:30px;
    font-style: normal;
    font-weight: 400;
    color:#000000;
}
/* as properties for both required images are the same, we are using them as one group */
.rightleftloop, .rightleftloop2 {
    position: absolute;
    -webkit-animation:rightleftloop;
    -webkit-animation-duration: 8.5s;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-fill-mode: both;
}
/* the second image animation will start with a delay of the half time as the original animation time as we set our images out of the frame from 50%-100% in the keyframes - this animation delay only comes up once before the start of the original animation */
.rightleftloop2 {
    -webkit-animation-delay: 4250ms;
}
/* one animation with pre-defined delay from 50%-100% of the time as content hidden so what ever animation we need will be done between 0%-50% */
@-webkit-keyframes rightleftloop {
    0% {
        -webkit-transform: translateX(-500px);
    }
    15% {
        -webkit-transform: translateX(20px);
    }
    35% {
        -webkit-transform: translateX(20px);
    }
    50% {
        -webkit-transform: translateX(-500px);
    }
    100% {
        -webkit-transform: translateX(-500px);
    }
}