2016-02-29 74 views
-1

我正在尝试创建一个显示我的云图像的CSS动画,然后在四秒钟的时间内云移动到左边直到它到达终点。无论出于何种原因,我都没有得到任何东西来展示我的尝试。CSS动画不显示

有没有人看到任何可能导致此不显示?

#cloud-container { 
 
    width: 50%; 
 
    position: relative; 
 
} 
 
#cloud-animation { 
 
    width: 80%; 
 
    height: 400px; 
 
    position: relative; 
 
    -webkit-animation-name: cloud; 
 
    -webkit-animation-duration: 4s; 
 
    -webkit-animation-iteration-count: 1; 
 
    -webkit-animation-direction: normal; 
 
    animation-name: cloud; 
 
    animation-duration: 4s; 
 
    animation-iteration-count: 1; 
 
    -webkit-animation-fill-mode: forwards; /* Chrome, Safari, Opera */ 
 
    animation-fill-mode: forwards; 
 
    animation-direction: normal; 
 
} 
 

 
@keyframes cloud { 
 
    0% { 
 
    background-image: url("http://optimumwebdesigns.com/images/cloud.JPG"); 
 
    background-repeat: no-repeat; 
 
    background-size: 100% auto; 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 30%; 
 
    top: 0px; 
 
    } 
 
    1000% { 
 
    background-image: url("http://optimumwebdesigns.com/images/cloud.JPG"); 
 
    background-repeat: no-repeat; 
 
    background-size: 100% auto; 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 10%; 
 
    top: 0px; 
 
    } 
 
} 
 
@-webkit-keyframes cloud { 
 
    0% { 
 
    background-image: url("http://optimumwebdesigns.com/images/cloud.JPG"); 
 
    background-repeat: no-repeat; 
 
    background-size: 100% auto; 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 30%; 
 
    top: 0px; 
 
    } 
 
    100% { 
 
    background-image: url("http://optimumwebdesigns.com/images/cloud.JPG"); 
 
    background-repeat: no-repeat; 
 
    background-size: 100% auto; 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 10%; 
 
    top: 0px; 
 
    } 
 
} 
 
}
<div id="cloud-container"> 
 
    <div id="cloud-animation"></div> 
 
</div>

+2

的背景规则的链接给404 – silviagreen

+0

我不知道404是如何被给予。它在我的文件管理器中打开。 – Becky

+0

@silviagreen我想出了路径问题。我必须把JPG大写。我也纠正了1000%的错误。不过,由于某些原因,照片变得越来越小,渐渐淡出。你看到任何理由为什么? – Becky

回答

3

它的工作原理,但你有两个错误:

  1. 的图像丢失(404错误)
  2. 你有1000%不会在第二个100%关键帧

您可以测试它与borde一起使用R:

#cloud-container { 
 
    width: 50%; 
 
    position: relative; 
 
} 
 
#cloud-animation { 
 
    background-image: url("http://dummyimage.com/600x400/000/fff"); 
 
    background-repeat: no-repeat; 
 
    background-size: 100% auto; 
 
    border: 1px solid black; 
 
    width: 80%; 
 
    height: 400px; 
 
    position: relative; 
 
    -webkit-animation-name: cloud; 
 
    -webkit-animation-duration: 4s; 
 
    -webkit-animation-iteration-count: 1; 
 
    -webkit-animation-direction: normal; 
 
    animation-name: cloud; 
 
    animation-duration: 4s; 
 
    animation-iteration-count: 1; 
 
    -webkit-animation-fill-mode: forwards; /* Chrome, Safari, Opera */ 
 
    animation-fill-mode: forwards; 
 
    animation-direction: normal; 
 
} 
 

 
@keyframes cloud { 
 
    0% { 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 30%; 
 
    top: 0px; 
 
    } 
 
    100% { 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 10%; 
 
    top: 0px; 
 
    } 
 
} 
 
@-webkit-keyframes cloud { 
 
    0% { 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 30%; 
 
    top: 0px; 
 
    } 
 
    100% { 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 10%; 
 
    top: 0px; 
 
    } 
 
} 
 
}
<div id="cloud-container"> 
 
    <div id="cloud-animation"></div> 
 
</div>

+0

我想出了路径问题。我必须把JPG大写。我也纠正了1000%的错误。不过,由于某些原因,照片变得越来越小,渐渐淡出。你看到任何理由为什么? – Becky

+0

我模拟了这个更像你的,并从每个关键帧中取出高度。工作很好。谢谢!@ – Becky

+0

你是否和queue()的问题一样@Becky?很高兴再次见到你 :) –

1

如果这是你想要的动画,然后我简单地添加背景图像规则到#云动画股利。

#cloud-container { 
 
    width: 50%; 
 
    position: relative; 
 
} 
 
#cloud-animation { 
 
    width: 80%; 
 
    height: 400px; 
 
    position: relative; 
 
    background-image: url("http://optimumwebdesigns.com/images/cloud.JPG"); 
 
/*ADD HERE THE background too*/ 
 
    -webkit-animation-name: cloud; 
 
    -webkit-animation-duration: 4s; 
 
    -webkit-animation-iteration-count: 1; 
 
    -webkit-animation-direction: normal; 
 
    animation-name: cloud; 
 
    animation-duration: 4s; 
 
    animation-iteration-count: 1; 
 
    -webkit-animation-fill-mode: forwards; /* Chrome, Safari, Opera */ 
 
    animation-fill-mode: forwards; 
 
    animation-direction: normal; 
 
} 
 

 
@keyframes cloud { 
 
    0% { 
 
    background-image: url("http://optimumwebdesigns.com/images/cloud.JPG"); 
 
    background-repeat: no-repeat; 
 
    background-size: 100% auto; 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 30%; 
 
    top: 0px; 
 
    } 
 
    1000% { 
 
    background-image: url("http://optimumwebdesigns.com/images/cloud.JPG"); 
 
    background-repeat: no-repeat; 
 
    background-size: 100% auto; 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 10%; 
 
    top: 0px; 
 
    } 
 
} 
 
@-webkit-keyframes cloud { 
 
    0% { 
 
    background-image: url("http://optimumwebdesigns.com/images/cloud.JPG"); 
 
    background-repeat: no-repeat; 
 
    background-size: 100% auto; 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 30%; 
 
    top: 0px; 
 
    } 
 
    100% { 
 
    background-image: url("http://optimumwebdesigns.com/images/cloud.JPG"); 
 
    background-repeat: no-repeat; 
 
    background-size: 100% auto; 
 
    height: 400px; 
 
    width: 400px; 
 
    left: 10%; 
 
    top: 0px; 
 
    } 
 
} 
 
}
<div id="cloud-container"> 
 
    <div id="cloud-animation"></div> 
 
</div>