2017-04-18 64 views
0

我從的jsfiddle這個示例代碼和發揮它,但代碼混淆我CSS動畫的延遲時間

.backgroundimg { 
 
    -webkit-background-size: cover; 
 
    \t -moz-background-size: cover; 
 
    \t -o-background-size: cover; 
 
    \t background-size: cover; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    height: 100%; 
 
    width: 100%; 
 

 
} 
 

 
#back5 { 
 
    background: url("http://duananhalotus.com/upload/album/0904234.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back4 { 
 
    background: url("http://www.chinadaily.com.cn/world/images/attachement/jpg/site1/20120806/d4bed9d534551189e67329.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back3 { 
 
    background: url("https://amazingslider.com/wp-content/uploads/2012/12/dandelion.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back2 { 
 
    background: url("https://cdn.pixabay.com/photo/2013/04/06/11/50/image-editing-101040_960_720.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back1 { 
 
    background: url("http://www.gettyimages.com/gi-resources/images/Embed/new/embed2.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
@keyframes backgroundchangeFadeInOut { 
 
    0% { 
 
    opacity:1; 
 
    } 
 
    17% { 
 
    opacity:1; 
 
    } 
 
    25% { 
 
    opacity:0; 
 
    } 
 
    92% { 
 
    opacity:0; 
 
    } 
 
    100% { 
 
    opacity:1; 
 
    } 
 
} 
 

 
@-webkit-keyframes backgroundchangeFadeInOut { 
 
    0% { 
 
    opacity:1; 
 
    } 
 
    17% { 
 
    opacity:1; 
 
    } 
 
    25% { 
 
    opacity:0; 
 
    } 
 
    92% { 
 
    opacity:0; 
 
    } 
 
    100% { 
 
    opacity:1; 
 
    } 
 
} 
 

 
#backgroundchange div:nth-of-type(1) { 
 
    animation-delay: 8s; 
 
    -webkit-animation-delay: 8s; 
 
} 
 
#backgroundchange div:nth-of-type(2) { 
 
    animation-delay: 6s; 
 
    -webkit-animation-delay: 6s; 
 
} 
 
#backgroundchange div:nth-of-type(3) { 
 
    animation-delay: 4s; 
 
    -webkit-animation-delay: 4s; 
 
} 
 
#backgroundchange div:nth-of-type(4) { 
 
    animation-delay: 2s; 
 
    -webkit-animation-delay: 2s; 
 
} 
 

 
#backgroundchange div:nth-of-type(5) { 
 
    animation-delay: 0; 
 
    -webkit-animation-delay: 0; 
 
} 
 

 
#backgroundchange div { 
 
animation-name: backgroundchangeFadeInOut; 
 
animation-timing-function: ease-in-out; 
 
animation-iteration-count: infinite; 
 
animation-duration: 8s; 
 

 
-webkit-animation-name: backgroundchangeFadeInOut; 
 
-webkit-animation-timing-function: ease-in-out; 
 
-webkit-animation-iteration-count: infinite; 
 
-webkit-animation-duration: 8s; 
 

 
}
<div class="inner"> 
 
       <div id="backgroundchange"> 
 
        <div class="backgroundimg" id="back1"></div> 
 
        <div class="backgroundimg" id="back2"></div> 
 
        <div class="backgroundimg" id="back3"></div> 
 
        <div class="backgroundimg" id="back4"></div> 
 
        <div class="backgroundimg" id="back5"></div> 
 
       </div> 
 
      </div>

它需要2秒的每個圖像交叉衰減到接下來,我試圖通過在每個類型中增加一秒來將其更改爲3秒,但不起作用。我需要你的幫助!

+0

你能告訴你試過嗎? – IiroP

+2

你試過0,3,6,9,12嗎? – Pete

+0

@IiroP我加了一個小提琴 –

回答

3

你需要增加的3增量的延遲從0開始與最後一個孩子,並在第一個孩子最後一個增量 - 下面我們從o到12

然後您需要將動畫長度更改爲最長延遲時間

.backgroundimg { 
 
    -webkit-background-size: cover; 
 
    \t -moz-background-size: cover; 
 
    \t -o-background-size: cover; 
 
    \t background-size: cover; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    height: 100%; 
 
    width: 100%; 
 

 
} 
 

 
#back5 { 
 
    background: url("http://duananhalotus.com/upload/album/0904234.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back4 { 
 
    background: url("http://www.chinadaily.com.cn/world/images/attachement/jpg/site1/20120806/d4bed9d534551189e67329.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back3 { 
 
    background: url("https://amazingslider.com/wp-content/uploads/2012/12/dandelion.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back2 { 
 
    background: url("https://cdn.pixabay.com/photo/2013/04/06/11/50/image-editing-101040_960_720.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back1 { 
 
    background: url("http://www.gettyimages.com/gi-resources/images/Embed/new/embed2.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
@keyframes backgroundchangeFadeInOut { 
 
    0% { 
 
    opacity:1; 
 
    } 
 
    17% { 
 
    opacity:1; 
 
    } 
 
    25% { 
 
    opacity:0; 
 
    } 
 
    92% { 
 
    opacity:0; 
 
    } 
 
    100% { 
 
    opacity:1; 
 
    } 
 
} 
 

 
@-webkit-keyframes backgroundchangeFadeInOut { 
 
    0% { 
 
    opacity:1; 
 
    } 
 
    17% { 
 
    opacity:1; 
 
    } 
 
    25% { 
 
    opacity:0; 
 
    } 
 
    92% { 
 
    opacity:0; 
 
    } 
 
    100% { 
 
    opacity:1; 
 
    } 
 
} 
 

 
#backgroundchange div:nth-of-type(1) { 
 
    animation-delay: 12s; 
 
    -webkit-animation-delay: 12s; 
 
} 
 
#backgroundchange div:nth-of-type(2) { 
 
    animation-delay: 9s; 
 
    -webkit-animation-delay: 9s; 
 
} 
 
#backgroundchange div:nth-of-type(3) { 
 
    animation-delay: 6s; 
 
    -webkit-animation-delay: 6s; 
 
} 
 
#backgroundchange div:nth-of-type(4) { 
 
    animation-delay: 3s; 
 
    -webkit-animation-delay: 3s; 
 
} 
 

 
#backgroundchange div:nth-of-type(5) { 
 
    animation-delay: 0; 
 
    -webkit-animation-delay: 0; 
 
} 
 

 
#backgroundchange div { 
 
animation-name: backgroundchangeFadeInOut; 
 
animation-timing-function: ease-in-out; 
 
animation-iteration-count: infinite; 
 
animation-duration: 12s; 
 

 
-webkit-animation-name: backgroundchangeFadeInOut; 
 
-webkit-animation-timing-function: ease-in-out; 
 
-webkit-animation-iteration-count: infinite; 
 
-webkit-animation-duration: 12s; 
 

 
}
<div class="inner"> 
 
    <div id="backgroundchange"> 
 
     <div class="backgroundimg" id="back1"></div> 
 
     <div class="backgroundimg" id="back2"></div> 
 
     <div class="backgroundimg" id="back3"></div> 
 
     <div class="backgroundimg" id="back4"></div> 
 
     <div class="backgroundimg" id="back5"></div> 
 
    </div> 
 
</div>

1

您還需要編輯動畫,持續時間12

.backgroundimg { 
 
    -webkit-background-size: cover; 
 
    \t -moz-background-size: cover; 
 
    \t -o-background-size: cover; 
 
    \t background-size: cover; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    height: 100%; 
 
    width: 100%; 
 

 
} 
 

 
#back5 { 
 
    background: url("http://duananhalotus.com/upload/album/0904234.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back4 { 
 
    background: url("http://www.chinadaily.com.cn/world/images/attachement/jpg/site1/20120806/d4bed9d534551189e67329.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back3 { 
 
    background: url("https://amazingslider.com/wp-content/uploads/2012/12/dandelion.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back2 { 
 
    background: url("https://cdn.pixabay.com/photo/2013/04/06/11/50/image-editing-101040_960_720.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back1 { 
 
    background: url("http://www.gettyimages.com/gi-resources/images/Embed/new/embed2.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
@keyframes backgroundchangeFadeInOut { 
 
    0% { 
 
    opacity:1; 
 
    } 
 
    17% { 
 
    opacity:1; 
 
    } 
 
    25% { 
 
    opacity:0; 
 
    } 
 
    92% { 
 
    opacity:0; 
 
    } 
 
    100% { 
 
    opacity:1; 
 
    } 
 
} 
 

 
@-webkit-keyframes backgroundchangeFadeInOut { 
 
    0% { 
 
    opacity:1; 
 
    } 
 
    17% { 
 
    opacity:1; 
 
    } 
 
    25% { 
 
    opacity:0; 
 
    } 
 
    92% { 
 
    opacity:0; 
 
    } 
 
    100% { 
 
    opacity:1; 
 
    } 
 
} 
 

 
#backgroundchange div:nth-of-type(1) { 
 
    animation-delay: 12s; 
 
    -webkit-animation-delay: 12s; 
 
} 
 
#backgroundchange div:nth-of-type(2) { 
 
    animation-delay: 9s; 
 
    -webkit-animation-delay: 9s; 
 
} 
 
#backgroundchange div:nth-of-type(3) { 
 
    animation-delay: 6s; 
 
    -webkit-animation-delay: 6s; 
 
} 
 
#backgroundchange div:nth-of-type(4) { 
 
    animation-delay: 3s; 
 
    -webkit-animation-delay: 3s; 
 
} 
 

 
#backgroundchange div:nth-of-type(5) { 
 
    animation-delay: 0; 
 
    -webkit-animation-delay: 0; 
 
} 
 

 
#backgroundchange div { 
 
animation-name: backgroundchangeFadeInOut; 
 
animation-timing-function: ease-in-out; 
 
animation-iteration-count: infinite; 
 
animation-duration: 12s; 
 

 
-webkit-animation-name: backgroundchangeFadeInOut; 
 
-webkit-animation-timing-function: ease-in-out; 
 
-webkit-animation-iteration-count: infinite; 
 
-webkit-animation-duration: 12s; 
 

 
}
<div class="inner"> 
 
       <div id="backgroundchange"> 
 
        <div class="backgroundimg" id="back1"></div> 
 
        <div class="backgroundimg" id="back2"></div> 
 
        <div class="backgroundimg" id="back3"></div> 
 
        <div class="backgroundimg" id="back4"></div> 
 
        <div class="backgroundimg" id="back5"></div> 
 
       </div> 
 
      </div>

1

這是工作3秒延時,想想也改變了WebKit的屬性..

.backgroundimg { 
 
    -webkit-background-size: cover; 
 
    \t -moz-background-size: cover; 
 
    \t -o-background-size: cover; 
 
    \t background-size: cover; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    height: 100%; 
 
    width: 100%; 
 

 
} 
 

 
#back5 { 
 
    background: url("http://duananhalotus.com/upload/album/0904234.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back4 { 
 
    background: url("http://www.chinadaily.com.cn/world/images/attachement/jpg/site1/20120806/d4bed9d534551189e67329.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back3 { 
 
    background: url("https://amazingslider.com/wp-content/uploads/2012/12/dandelion.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back2 { 
 
    background: url("https://cdn.pixabay.com/photo/2013/04/06/11/50/image-editing-101040_960_720.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
#back1 { 
 
    background: url("http://www.gettyimages.com/gi-resources/images/Embed/new/embed2.jpg") no-repeat center fixed; 
 
    z-index: -1; 
 
} 
 

 
@keyframes backgroundchangeFadeInOut { 
 
    0% { 
 
    opacity:1; 
 
    } 
 
    17% { 
 
    opacity:1; 
 
    } 
 
    25% { 
 
    opacity:0; 
 
    } 
 
    92% { 
 
    opacity:0; 
 
    } 
 
    100% { 
 
    opacity:1; 
 
    } 
 
} 
 

 
@-webkit-keyframes backgroundchangeFadeInOut { 
 
    0% { 
 
    opacity:1; 
 
    } 
 
    17% { 
 
    opacity:1; 
 
    } 
 
    25% { 
 
    opacity:0; 
 
    } 
 
    92% { 
 
    opacity:0; 
 
    } 
 
    100% { 
 
    opacity:1; 
 
    } 
 
} 
 

 
#backgroundchange div:nth-of-type(1) { 
 
    animation-delay: 12s; 
 
    -webkit-animation-delay: 12s; 
 
} 
 
#backgroundchange div:nth-of-type(2) { 
 
    animation-delay: 9s; 
 
    -webkit-animation-delay:9s; 
 
} 
 
#backgroundchange div:nth-of-type(3) { 
 
    animation-delay: 6s; 
 
    -webkit-animation-delay: 6s; 
 
} 
 
#backgroundchange div:nth-of-type(4) { 
 
    animation-delay:3s; 
 
    -webkit-animation-delay: 3s; 
 
} 
 

 
#backgroundchange div:nth-of-type(5) { 
 
    animation-delay: 0; 
 
    -webkit-animation-delay: 0; 
 
} 
 

 
#backgroundchange div { 
 
animation-name: backgroundchangeFadeInOut; 
 
animation-timing-function: ease-in-out; 
 
animation-iteration-count: infinite; 
 
animation-duration: 12s; 
 

 
-webkit-animation-name: backgroundchangeFadeInOut; 
 
-webkit-animation-timing-function: ease-in-out; 
 
-webkit-animation-iteration-count: infinite; 
 
-webkit-animation-duration: 12s; 
 

 
}
<div class="inner"> 
 
       <div id="backgroundchange"> 
 
        <div class="backgroundimg" id="back1"></div> 
 
        <div class="backgroundimg" id="back2"></div> 
 
        <div class="backgroundimg" id="back3"></div> 
 
        <div class="backgroundimg" id="back4"></div> 
 
        <div class="backgroundimg" id="back5"></div> 
 
       </div> 
 
      </div>