我想要動起來應該從右到左像雲層一樣移動的地板,但它的工作原理是問題是它溢出容器外。我怎樣才能防止這種情況發生?對不起,我是新來的CSS動畫。提前致謝。動畫圖像像它從右向左移動
這裏是我做的小提琴:點擊here
.container {
width: 50%;
margin: 0 auto;
text-align: center;
}
#clouds{
padding: 100px 0;
background: #3598dc;
background: -webkit-linear-gradient(top, #3598dc 0%, #fff 100%);
background: -linear-gradient(top, #3598dc 0%, #fff 100%);
background: -moz-linear-gradient(top, #3598dc 0%, #fff 100%);
}
.cloud {
width: 200px; height: 60px;
background: #fff;
border-radius: 200px;
-moz-border-radius: 200px;
-webkit-border-radius: 200px;
position: relative;
}
.cloud:before, .cloud:after {
content: '';
position: absolute;
background: #fff;
width: 100px; height: 80px;
position: absolute; top: -15px; left: 10px;
border-radius: 100px;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
-webkit-transform: rotate(30deg);
transform: rotate(30deg);
-moz-transform: rotate(30deg);
}
.cloud:after {
width: 120px; height: 120px;
top: -55px; left: auto; right: 15px;
}
#character{
margin-top: -120px;
background:url(http://i.imgur.com/Zjsbcni.png);
width: 84px;
height: 126px;
animation: walk 1.0s steps(6) infinite;
margin-left: 425px;
}
#flooring {
height: 39px;
background-image: url(http://i.imgur.com/usFekrp.png);
animation: movefloor 20s linear infinite;
overflow: hidden;
}
@keyframes movefloor {
0% {margin-left: 1000px;}
100% {margin-left: -1000px;}
}
@keyframes walk {
from { background-position: 0px; }
to { background-position: -500px; }
}
.x1 {
-webkit-animation: moveclouds 15s linear infinite;
-moz-animation: moveclouds 15s linear infinite;
-o-animation: moveclouds 15s linear infinite;
}
.x2 {
left: 200px;
-webkit-transform: scale(0.6);
-moz-transform: scale(0.6);
transform: scale(0.6);
opacity: 0.6; /*opacity proportional to the size*/
-webkit-animation: moveclouds 25s linear infinite;
-moz-animation: moveclouds 25s linear infinite;
-o-animation: moveclouds 25s linear infinite;
}
.x3 {
left: 252px;
top: -200px;
-webkit-transform: scale(0.8);
-moz-transform: scale(0.8);
transform: scale(0.8);
opacity: 0.8; /*opacity proportional to the size*/
-webkit-animation: moveclouds 20s linear infinite;
-moz-animation: moveclouds 20s linear infinite;
-o-animation: moveclouds 20s linear infinite;
}
@-webkit-keyframes moveclouds {
0% {margin-left: 1000px;}
100% {margin-left: -1000px;}
}
@-moz-keyframes moveclouds {
0% {margin-left: 1000px;}
100% {margin-left: -1000px;}
}
@-o-keyframes moveclouds {
0% {margin-left: 1000px;}
100% {margin-left: -1000px;}
}
<div class="container">
<div id="clouds">
<div class="cloud x1"></div>
<div class="cloud x2"></div>
<div class="cloud x3"></div>
<div class="cloud x4"></div>
<div class="cloud x5"></div>
</div>
<div id="character"></div>
<div id="flooring"></div>
</div>
'溢出:hidden'? – gcampbell
請查看參考工作小提琴 – claudios
添加'溢出:hidden'到div'#clouds' – Pugazh