仅使用 CSS 交叉淡入淡出多个背景图像 - 单页面设计

2024-02-12

我正在使用多个 div 构建一个响应式单页网站,这些 div 可缩放到用户浏览器的高度和宽度。我想让多个背景图像在网站上的一个 div 内无限循环地交叉淡入淡出。我尝试按照本教程进行操作:http://css3.bradshawenterprises.com/cfimg/ 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 浏览器,请务必使用-webkit-CSS 动画的前缀:

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;

}

FIDDLE http://jsfiddle.net/h2fzvyr5/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

仅使用 CSS 交叉淡入淡出多个背景图像 - 单页面设计 的相关文章

随机推荐

  • 在 UIWebView 中执行操作后隐藏文本选择手柄

    我有几个定制UIMenuItems通过选择来执行操作UIWebView 在该选择上运行操作后 我想隐藏选择手柄 就像copy does 我尝试过使用window getSelection removeAllRanges 那是有效的windo
  • Networkx - 从社区创建图表

    使用以下工作代码 import netowkx as nx import networkx algorithms community as nx comm G nx karate club graph Find the communitie
  • 当我的子类位于不同的包中时,为什么我的子类无法访问其超类的受保护变量?

    我有一个抽象类 relation包装内database relation和它的一个子类 Join 在包中database operations relation有一个名为的受保护成员mStructure In Join public Joi
  • 在 JBoss 中我可以配置“共享库”位置吗?

    我在开发环境中使用 JBoss 4 2 2 GA 应用程序服务器 我有一个 WAR 文件 MyWar war和一个 JAR 文件ExternalJar jar 这些文件的结构如下 应用程序 WAR 文件 MyWar war AppClass
  • 复制功能如何工作? [关闭]

    Closed 这个问题需要细节或清晰度 help closed questions 目前不接受答案 我不明白如何copy函数基于文档工作 copy 内置函数将元素从源切片复制到 目标切片 作为一种特殊情况 它还会从 字符串到字节切片 源和目
  • 如何在上传到服务器之前调整/压缩 Android 中的相机图像或图库图像?

    我必须上传可以从图库中选择或用相机拍摄的图像 我已经成功地做到了这一点 但问题是 有时图像大小为 1MB 所以上传到服务器需要更多时间 我需要在上传之前调整此图像的大小 这个怎么做 public void onActivityResult
  • 从 JSON 创建数组的数组

    我在 ajax 调用后收到以下内容response在 PHP 中使用json encode 2013 02 24 0 2013 02 25 0 2013 02 26 1 2013 02 27 6 2013 02 28 6 2013 03 0
  • 无法在cygwin上安装uwsgi

    我的主要操作系统是 Windows 10 但我使用 cygwin 作为终端 通过安装uwsgi时pip3 install uwsgi命令 它失败并显示错误消息 AttributeError module os has no attribut
  • 我如何全局安装 sbt 插件

    我从github下载了android sdk plugin 文档说我需要全局安装插件 将插件全局安装到 sbt plugins 或 sbt 0 13 plugins 分别适用于 0 12 和 0 13 addSbtPlugin com ha
  • 实体(空)不符合键“title”的键值编码

    我正在尝试让 RestKit 和 CoreData 一起工作 我越来越接近了 但我收到以下错误 CoreData error Failed to call designated initializer on NSManagedObject
  • 单个应用程序中的多个 RCTRootView

    我正在创建一个 React Native 应用程序 但我需要使用 Objective C 来构建我的自定义 UIView 但问题是这个 UIView 需要显示反应内容 例如反应文本输入和按钮 我正在考虑向自定义 UIView 添加 RCTR
  • 位图.保存“一般错误”

    当我运行我的应用程序时 出现以下错误 GDI 中发生一般错误 我环顾四周 发现人们也有类似的错误 但没有找到真正的解决方案 或者实施起来确实很痛苦 那些没有得到解决方案的人还没有发布他们的代码 所以我想我不妨尝试一下并提出另一个关于如何修复
  • @login_required 正在丢失当前指定的语言

    我在用i18n patterns使我的应用程序国际化并且它正在工作 除非我单击需要登录的链接 受保护的视图 login required装饰器 我被重定向到默认语言的登录表单 而不是当前活动的语言 如何保留活动 URL 换句话说 当在法语部
  • rawQuery(查询,选择参数)

    我想使用选择查询从表中检索数据 我已经发现 rawQuery query selectionArgs 的方法SQLiteDatabase类来检索数据 但我不知道如何query and selectionArgs应该传递给rawQuery m
  • 你能从 sklearn 网格搜索 (GridSearchCV) 中获得所有估计器吗?

    我最近使用测试了许多超参数组合sklearn model selection GridSearchCV 我想知道是否有一种方法可以调用在此过程中接受过培训的所有先前估算器 search GridSearchCV estimator my e
  • 分布式缓存

    我正在 opensuse linux 上使用 hadoop 19 我没有使用任何集群 而是在我的机器本身上运行我的 hadoop 代码 我遵循放入分布式缓存的标准技术 但我不是一次又一次地从分布式缓存访问文件 而是将文件的内容存储在一个数组
  • 如何知道 C 函数 free 是否正常工作?

    我发现以下代码的结果存在一些差异 include
  • 为什么Java中没有AtomicBoolean数组数据类型?

    我注意到有NOJava 中的 AtomicBooleanArray 数据类型类似于 AtomicIntegerArray 虽然我可以使用 AtomicBoolean 来满足当前的需求 但我很想了解为什么 AtomicBooleanArray
  • 如何在 JavaScript 中记录返回

    我正在为浏览器应用程序的工作项目编写自己的库 并且在决定如何注释代码时遇到同样的老问题 我正在尝试遵循JsDoc https code google com p jsdoc toolkit w list语法 但可能会继续谷歌闭包编译器 ht
  • 仅使用 CSS 交叉淡入淡出多个背景图像 - 单页面设计

    我正在使用多个 div 构建一个响应式单页网站 这些 div 可缩放到用户浏览器的高度和宽度 我想让多个背景图像在网站上的一个 div 内无限循环地交叉淡入淡出 我尝试按照本教程进行操作 http css3 bradshawenterpri