html - 过渡时间不适用于 CSS3

标签 html css

我正在制作一个具有完整背景图像转换的网站。 问题是动画,我无法让它们正常工作。我希望它们在图像之间没有黑屏的情况下从一个淡入另一个。这是我的实时网站:http://testes-cmt.bl.ee

我已经尝试了很多方法,但我无法解决这个问题,即使尝试更改时间也是如此。

有人知道怎么解决吗? 到目前为止,这是我的代码:

HTML:

<ul class="cb-slideshow">
  <li><span>Image 01</span></li>
  <li><span>Image 02</span></li>
  <li><span>Image 03</span></li>
  <li><span>Image 04</span></li>
</ul>

CSS:

.cb-slideshow li span { 
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0px;
    left: 0px;
    color: transparent;
    background-size: cover;
    background-position: 50% 50%;
    background-repeat: none;
    opacity: 0;
    z-index: 0;
    -webkit-backface-visibility: hidden;
    -webkit-animation: imageAnimation 32s linear infinite 0s;
    -moz-animation: imageAnimation 32s linear infinite 0s;
    -o-animation: imageAnimation 32s linear infinite 0s;
    -ms-animation: imageAnimation 32s linear infinite 0s;
    animation: imageAnimation 32s linear infinite 0s; 
}
.cb-slideshow li div { 
    z-index: 1000;
    position: absolute;
    bottom: 30px;
    left: 0px;
    width: 100%;
    text-align: center;
    opacity: 0;
    color: #fff;
    -webkit-animation: titleAnimation 32s linear infinite 0s;
    -moz-animation: titleAnimation 32s linear infinite 0s;
    -o-animation: titleAnimation 32s linear infinite 0s;
    -ms-animation: titleAnimation 32s linear infinite 0s;
    animation: titleAnimation 32s linear infinite 0s; 
}

.cb-slideshow li:nth-child(1) span { 
    background-image: url(../images/1.jpg) 
}
.cb-slideshow li:nth-child(2) span { 
    background-image: url(../images/2.jpg);
    -webkit-animation-delay: 8s;
    -moz-animation-delay: 8s;
    -o-animation-delay: 8s;
    -ms-animation-delay: 8s;
    animation-delay: 8s; 
}
.cb-slideshow li:nth-child(3) span { 
    background-image: url(../images/3.jpg);
    -webkit-animation-delay: 16s;
    -moz-animation-delay: 16s;
    -o-animation-delay: 16s;
    -ms-animation-delay: 16s;
    animation-delay: 16s; 
}
.cb-slideshow li:nth-child(4) span { 
    background-image: url(../images/4.jpg);
    -webkit-animation-delay: 24s;
    -moz-animation-delay: 24s;
    -o-animation-delay: 24s;
    -ms-animation-delay: 24s;
    animation-delay: 24s; 
}


.cb-slideshow li:nth-child(2) div { 
    -webkit-animation-delay: 8s;
    -moz-animation-delay: 8s;
    -o-animation-delay: 8s;
    -ms-animation-delay: 8s;
    animation-delay: 8s; 
}
.cb-slideshow li:nth-child(3) div { 
    -webkit-animation-delay: 16s;
    -moz-animation-delay: 16s;
    -o-animation-delay: 16s;
    -ms-animation-delay: 16s;
    animation-delay: 16s; 
}
.cb-slideshow li:nth-child(4) div { 
    -webkit-animation-delay: 24s;
    -moz-animation-delay: 24s;
    -o-animation-delay: 24s;
    -ms-animation-delay: 24s;
    animation-delay: 24s; 
}


@-webkit-keyframes imageAnimation { 
    0% { opacity: 0;
    -webkit-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -webkit-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}
@-moz-keyframes imageAnimation { 
    0% { opacity: 0;
    -moz-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -moz-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}
@-o-keyframes imageAnimation { 
    0% { opacity: 0;
    -o-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -o-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}
@-ms-keyframes imageAnimation { 
    0% { opacity: 0;
    -ms-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -ms-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}
@keyframes imageAnimation { 
    0% { opacity: 0;
    animation-timing-function: ease-in; }
    8% { opacity: 1;
         animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}

最佳答案

我发现使过渡淡入淡出而不是通过黑色的最快方法是调整 @keyframes 以延长 opacity: 1 时间:

@keyframes imageAnimation { 
    0% { opacity: 0;
    animation-timing-function: ease-in; }
    8% { opacity: 1;
         animation-timing-function: ease-out; }
    30% { opacity: 1 }
    40% { opacity: 0 }
    100% { opacity: 0 }
}

像这样的东西 JSFiddle .

关于html - 过渡时间不适用于 CSS3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22313497/

相关文章:

android - 在 phonegap 中模拟 gps 位置

javascript - 如何使用 ajax 上传文本字段和文件?

javascript - 使用 jQuery/hide 隐藏动态附加的 div 不起作用

css - 多个 HTML 5 Canvas

jquery - 向左过渡幻灯片

css - 边栏中的填充问题

html - 在 <td> 元素中使用类 - 样式

html - 如何使导航菜单居中

html - 表格中 <td> 元素下的 CSS 三 Angular 形

html - 如何更改菜单栏中事件链接的背景颜色?