仅使用 CSS 交叉淡化多个背景图像 - 单页设计
Crossfade Multiple Background Images Using CSS Only - Single Page Design
我正在使用多个 div 构建一个响应式单页网站,这些 div 可以缩放到用户浏览器的高度和宽度。我想在网站上的一个 div 中以无限循环的方式将多个背景图像交叉淡化到另一个图像中。我已尝试按照本教程:http://css3.bradshawenterprises.com/cfimg/ 尽我所能,但无法使其适应我的特定需求。我相信我遗漏了教程中的一段代码,该代码是该系统不可或缺的一部分,但我一生都无法理解我必须实现哪些部分以及我不能实现哪些部分才能使其在本系统中工作案子。 (部分原因是我的笨拙,部分原因是教程被奇怪地分段了。)
我完全是 Web 开发的菜鸟,所以如果我的代码有严重错误,请原谅我(并纠正我)。
<html>
<body>
<div id="home" class="panel">
<div class="inner">
<div id="backgroundchange">
<div id="back1"></div>
<div id="back2"></div>
<div id="back3"></div>
<div id="back4"></div>
<div id="back5"></div>
</div>
</div>
</div>
<body>
<html>
<!--Div Formatting-->
html, body {
height: 100%;
margin: 0;
}
.panel {
font-family: "Source Sans Pro", Helvetica, Arial, sans-serif;
color: white;
height: 100%;
min-width: 100%;
text-align: center;
display: table;
margin: 0;
background: #1c1c1c;
padding: 0 0;
}
.panel .inner {
display: table-cell;
vertical-align: middle;
}
<!--Background Animation-->
#backgroundchange.backgroundimg {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
transition: background-image 1s ease-in-out;
}
#back1 {
background: url(../img/Back1.png) no-repeat center center fixed;
}
#back2 {
background: url(../img/Back2.png) no-repeat center center fixed;
}
#back3 {
background: url(../img/Back3.png) no-repeat center center fixed;
}
#back4 {
background: url(../img/Back4.png) no-repeat center center fixed;
}
@keyframes cf4FadeInOut {
0% {
opacity: 1;
}
17% {
opacity: 1;
}
25% {
opacity: 0;
}
92% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#backgroundchange div:nth-of-type(1) {
animation-delay: 6s;
}
#backgroundchange div:nth-of-type(2) {
animation-delay: 4s;
}
#backgroundchange div:nth-of-type(3) {
animation-delay: 2s;
}
#backgroundchange div:nth-of-type(4) {
animation-delay: 0;
}
提前致谢。
我相信这就是你想要的。我不确定你使用的是什么浏览器,但如果它是像 chrome 这样的 webkit 浏览器,请务必在你的 css 动画上使用 -webkit-
前缀:
HTML
<div id="home" class="panel">
<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>
</div>
CSS
html, body {
height: 100%;
margin: 0;
}
.panel {
font-family: "Source Sans Pro", Helvetica, Arial, sans-serif;
color: white;
height: 100%;
min-width: 100%;
text-align: center;
display: table;
margin: 0;
background: #1c1c1c;
padding: 0 0;
}
.panel .inner {
display: table-cell;
vertical-align: middle;
}
.backgroundimg {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
#back1 {
background: url("http://www.placecage.com/500/700") no-repeat center fixed;
}
#back2 {
background: url("http://www.placecage.com/500/600") no-repeat center fixed;
}
#back3 {
background: url("http://www.placecage.com/500/500") no-repeat center fixed;
}
#back4 {
background: url("http://www.placecage.com/500/800") no-repeat center fixed;
}
#back5 {
background: url("http://www.placecage.com/500/900") no-repeat center fixed;
}
@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 构建一个响应式单页网站,这些 div 可以缩放到用户浏览器的高度和宽度。我想在网站上的一个 div 中以无限循环的方式将多个背景图像交叉淡化到另一个图像中。我已尝试按照本教程:http://css3.bradshawenterprises.com/cfimg/ 尽我所能,但无法使其适应我的特定需求。我相信我遗漏了教程中的一段代码,该代码是该系统不可或缺的一部分,但我一生都无法理解我必须实现哪些部分以及我不能实现哪些部分才能使其在本系统中工作案子。 (部分原因是我的笨拙,部分原因是教程被奇怪地分段了。)
我完全是 Web 开发的菜鸟,所以如果我的代码有严重错误,请原谅我(并纠正我)。
<html>
<body>
<div id="home" class="panel">
<div class="inner">
<div id="backgroundchange">
<div id="back1"></div>
<div id="back2"></div>
<div id="back3"></div>
<div id="back4"></div>
<div id="back5"></div>
</div>
</div>
</div>
<body>
<html>
<!--Div Formatting-->
html, body {
height: 100%;
margin: 0;
}
.panel {
font-family: "Source Sans Pro", Helvetica, Arial, sans-serif;
color: white;
height: 100%;
min-width: 100%;
text-align: center;
display: table;
margin: 0;
background: #1c1c1c;
padding: 0 0;
}
.panel .inner {
display: table-cell;
vertical-align: middle;
}
<!--Background Animation-->
#backgroundchange.backgroundimg {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
transition: background-image 1s ease-in-out;
}
#back1 {
background: url(../img/Back1.png) no-repeat center center fixed;
}
#back2 {
background: url(../img/Back2.png) no-repeat center center fixed;
}
#back3 {
background: url(../img/Back3.png) no-repeat center center fixed;
}
#back4 {
background: url(../img/Back4.png) no-repeat center center fixed;
}
@keyframes cf4FadeInOut {
0% {
opacity: 1;
}
17% {
opacity: 1;
}
25% {
opacity: 0;
}
92% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#backgroundchange div:nth-of-type(1) {
animation-delay: 6s;
}
#backgroundchange div:nth-of-type(2) {
animation-delay: 4s;
}
#backgroundchange div:nth-of-type(3) {
animation-delay: 2s;
}
#backgroundchange div:nth-of-type(4) {
animation-delay: 0;
}
提前致谢。
我相信这就是你想要的。我不确定你使用的是什么浏览器,但如果它是像 chrome 这样的 webkit 浏览器,请务必在你的 css 动画上使用 -webkit-
前缀:
HTML
<div id="home" class="panel">
<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>
</div>
CSS
html, body {
height: 100%;
margin: 0;
}
.panel {
font-family: "Source Sans Pro", Helvetica, Arial, sans-serif;
color: white;
height: 100%;
min-width: 100%;
text-align: center;
display: table;
margin: 0;
background: #1c1c1c;
padding: 0 0;
}
.panel .inner {
display: table-cell;
vertical-align: middle;
}
.backgroundimg {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
#back1 {
background: url("http://www.placecage.com/500/700") no-repeat center fixed;
}
#back2 {
background: url("http://www.placecage.com/500/600") no-repeat center fixed;
}
#back3 {
background: url("http://www.placecage.com/500/500") no-repeat center fixed;
}
#back4 {
background: url("http://www.placecage.com/500/800") no-repeat center fixed;
}
#back5 {
background: url("http://www.placecage.com/500/900") no-repeat center fixed;
}
@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;
}