Tips:当你看到这个提示的时候,说明当前的文章是由原emlog博客系统搬迁至此的,文章发布时间已过于久远,编排和内容不一定完整,还请谅解`

CSS3随机背景图片切换特效

日期:2018-5-16 阿珏 css 浏览:4572次 评论:16条

css3的随机背景图片淡入淡出切换特效  演示效果如本篇文章背景所示

看大家扒我的

幻想领域二次元限定版扒

的比较累,扒了大半个小时的,抽空整理一下发出来

设计之初本来是打算使用jQuery进行实现的,但是注意到了css3的@keyframes 规则,css3已经强大到曾经只有js才能实现的效果

定义和用法

通过 @keyframes 规则,您能够创建动画。

创建动画的原理是,将一套 CSS 样式逐渐变化为另一套样式。

在动画过程中,您能够多次改变这套 CSS 样式。

以百分比来规定改变发生的时间,或者通过关键词 "from" 和 "to",等价于 0% 和 100%。

0% 是动画的开始时间,100% 动画的结束时间。

为了获得最佳的浏览器支持,您应该始终定义 0% 和 100% 选择器。

注释:

请使用动画属性来控制动画的外观,同时将动画与选择器绑定。

核心css部分(记得切换图片地址)

body {
background: #000;
background-attachment: fixed;
word-wrap: break-word;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
background-repeat: no-repeat
} ul {
list-style: none
} .cb-slideshow li:nth-child(1) span {
background-image: url(https://random.52ecy.cn/randbg.php?v=1520341099)
} .cb-slideshow li:nth-child(2) span {
background-image: url(https://random.52ecy.cn/randbg.php?v=1520341159)
} .cb-slideshow li:nth-child(3) span {
background-image: url(https://random.52ecy.cn/randbg.php?v=1520341149)
} .cb-slideshow li:nth-child(4) span {
background-image: url(https://random.52ecy.cn/randbg.php?v=1520341139)
} .cb-slideshow li:nth-child(5) span {
background-image: url(https://random.52ecy.cn/randbg.php?v=1520341129)
} .cb-slideshow li:nth-child(6) span {
background-image: url(https://random.52ecy.cn/randbg.php?v=1520341119)
} .cb-slideshow,.cb-slideshow:after {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -2
} .cb-slideshow:after {
content: ''
} .cb-slideshow li span {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
color: transparent;
background-size: cover;
background-position: 50% 50%;
background-repeat: none;
opacity: 0;
z-index: -2;
-webkit-backface-visibility: hidden;
-webkit-animation: imageAnimation 36s linear infinite 0s;
-moz-animation: imageAnimation 36s linear infinite 0s;
-o-animation: imageAnimation 36s linear infinite 0s;
-ms-animation: imageAnimation 36s linear infinite 0s;
animation: imageAnimation 36s linear infinite 0s
} .cb-slideshow li:nth-child(2) span {
-webkit-animation-delay: 6s;
-moz-animation-delay: 6s;
-o-animation-delay: 6s;
-ms-animation-delay: 6s;
animation-delay: 6s
} .cb-slideshow li:nth-child(3) span {
-webkit-animation-delay: 12s;
-moz-animation-delay: 12s;
-o-animation-delay: 12s;
-ms-animation-delay: 12s;
animation-delay: 12s
} .cb-slideshow li:nth-child(4) span {
-webkit-animation-delay: 18s;
-moz-animation-delay: 18s;
-o-animation-delay: 18s;
-ms-animation-delay: 18s;
animation-delay: 18s
} .cb-slideshow li:nth-child(5) span {
-webkit-animation-delay: 24s;
-moz-animation-delay: 24s;
-o-animation-delay: 24s;
-ms-animation-delay: 24s;
animation-delay: 24s
} .cb-slideshow li:nth-child(6) span {
-webkit-animation-delay: 30s;
-moz-animation-delay: 30s;
-o-animation-delay: 30s;
-ms-animation-delay: 30s;
animation-delay: 30s
} @-webkit-keyframes imageAnimation {
0% {
opacity: 0;
-webkit-animation-timing-function: ease-in
} 8% {
opacity: 1;
-webkit-transform: scale(1.05);
-webkit-animation-timing-function: ease-out
} 17% {
opacity: 1;
-webkit-transform: scale(1.1) rotate(0)
} 25% {
opacity: 0;
-webkit-transform: scale(1.1) rotate(0)
} 100% {
opacity: 0
}
}

当然还是需要配合HTML代码的

HTML部分(其中的文字部分和

  • 的数量是可以随意更改的)

    ```

    • 幻想
    • 领域
    • 一个
    • 专业的
    • 二次元
    • 图床

    ```

    注意:

  • 的数量要和css对应上,并且至少要两个以上。另外ie浏览器是不支持CSS3的特效
    • 苟利
    • 国家
    • 生死以
    • 岂能
    • 祸福
    • 趋避之

    body { background: no-repeat fixed rgba(0, 0, 0, 1); word-wrap: break-word; -webkit-background-size: cover; -moz-background-size: cover }
    ul { z-index: 99; list-style: none }
    li { list-style: none }
    .cb-slideshow li:nth-child(0n+1) span { background-image: url("https://random.52ecy.cn/randbg.php?v=1520341099") }
    .cb-slideshow li:nth-child(0n+2) span { background-image: url("https://random.52ecy.cn/randbg.php?v=1520341159") }
    .cb-slideshow li:nth-child(0n+3) span { background-image: url("https://random.52ecy.cn/randbg.php?v=1520341149") }
    .cb-slideshow li:nth-child(0n+4) span { background-image: url("https://random.52ecy.cn/randbg.php?v=1520341139") }
    .cb-slideshow li:nth-child(0n+5) span { background-image: url("https://random.52ecy.cn/randbg.php?v=1520341129") }
    .cb-slideshow li:nth-child(0n+6) span { background-image: url("https://random.52ecy.cn/randbg.php?v=1520341119") }
    .cb-slideshow, .cb-slideshow:after { position: fixed; width: 100%; height: 100%; top: 0; left: 0; z-index: -2 }
    .cb-slideshow:after { content: "" }
    .cb-slideshow li span { width: 100%; height: 100%; position: absolute; top: 0; left: 0; color: rgba(0, 0, 0, 0); background-size: cover; background-position: center; opacity: 0; z-index: -2; -webkit-backface-visibility: hidden; -webkit-animation: imageAnimation 36s linear infinite 0s; -moz-animation: imageAnimation 36s linear infinite 0s; -o-animation: imageAnimation 36s linear infinite 0s; -ms-animation: imageAnimation 36s linear infinite 0s; animation: 36s linear 0s infinite imageanimation }
    .cb-slideshow li:nth-child(0n+2) span { -webkit-animation-delay: 6s; -moz-animation-delay: 6s; -o-animation-delay: 6s; -ms-animation-delay: 6s; animation-delay: 6s }
    .cb-slideshow li:nth-child(0n+3) span { -webkit-animation-delay: 12s; -moz-animation-delay: 12s; -o-animation-delay: 12s; -ms-animation-delay: 12s; animation-delay: 12s }
    .cb-slideshow li:nth-child(0n+4) span { -webkit-animation-delay: 18s; -moz-animation-delay: 18s; -o-animation-delay: 18s; -ms-animation-delay: 18s; animation-delay: 18s }
    .cb-slideshow li:nth-child(0n+5) span { -webkit-animation-delay: 24s; -moz-animation-delay: 24s; -o-animation-delay: 24s; -ms-animation-delay: 24s; animation-delay: 24s }
    .cb-slideshow li:nth-child(0n+6) span { -webkit-animation-delay: 30s; -moz-animation-delay: 30s; -o-animation-delay: 30s; -ms-animation-delay: 30s; animation-delay: 30s }
    @-webkit-keyframes imageAnimation{0%{opacity:0;-webkit-animation-timing-function:ease-in}8%{opacity:1;-webkit-transform:scale(1.05);-webkit-animation-timing-function:ease-out}17%{opacity:1;-webkit-transform:scale(1.1) rotate(0)}25%{opacity:0;-webkit-transform:scale(1.1) rotate(0)}100%{opacity:0}}

    网友评论:

    凡人多烦事 1年前 (2020-02-16)

    这个怎么搞得了嘞?我研究了半天,还是全黑屏[#aru_15][#aru_15]

    阿珏 1年前 (2020-02-16)

    @凡人多烦事:可以在群里at下我发个网址瞅瞅

    凡人多烦事 1年前 (2020-02-17)

    @阿珏:群里面那个是你呀?[#aru_15]叫我主人还是本群群主[#aru_16]

    365cent 3年前 (2018-10-12)

    翻牌子

    我觉得不行 3年前 (2018-08-30)

    果然不能纯抄代码,第一行的background: #000;用了之后背景全黑没有特效,排查了后发现改成background-color:rgba(0,0,0,0);成功了,还有代码里缺分号作为一个强迫症的我有点不能接受。不过还是得感谢博主分享的特效代码!

    阿珏 3年前 (2018-08-31)

    @我觉得不行:有些样式是要根据你实际情况更改的[#aru_36]。css在线格式化后,默认最后一行样式都是不加分号的[#aru_11]

    墨渊 3年前 (2018-06-20)

    这图片无敌了

    墨渊 3年前 (2018-06-20)

    审核元素,怎么屏蔽的,这个有点6,直接死机

    阿珏 3年前 (2018-06-21)

    @墨渊:低调[#aru_130]

    腾讯视频 3年前 (2018-06-14)

    不能复制?那编写这篇文章干嘛?

    阿珏 3年前 (2018-06-14)

    @腾讯视频:给你复制扒我文章?

    腾讯视频 3年前 (2018-06-14)

    @阿珏:真要扒文章是个人都能做到吧,只是对于博客禁右感到莫名所以

    梦如 3年前 (2018-05-17)

    已解决,强制刷新CSS   ver=

    梦奴 3年前 (2018-05-16)

    换的是随机图API的链接  在360极速浏览器里不会刷新随机图

    阿珏 3年前 (2018-05-17)

    @梦奴:被浏览器缓存了,加个时间戳就可以了

    梦如 3年前 (2018-05-16)

    可以,赞一个

  • CSS3随机背景图片切换特效的更多相关文章

    1. css3全屏背景图片切换特效

      效果体验:http://hovertree.com/texiao/css3/10/ 一般做图片切换效果,都会使用JS或者jQuery脚本,今天发现,其实只用CSS也可以实现.试试效果吧. 效果图: 代 ...

    2. 基于HTML5 SVG和CSS3炫酷蹦床式图片切换特效

      今天给大家分享一款效果非常炫酷的HTML5 SVG和CSS3蹦床式图片切换特效插件.该图片切换插件在进行图片切换时,整个屏幕就像一张大蹦床一样,将图片弹射出去,切换到另一张图片,效果非常有创意.效果图 ...

    3. jquery背景自动切换特效

      查看效果网址:http://keleyi.com/a/bjad/4kwkql05.htm 本特效的jquery版本只支持1.9.0以下. 代码如下: <!DOCTYPE html PUBLIC ...

    4. jQuery旋转木马仿3D效果的图片切换特效代码

      用jQuery实现的一款仿3D效果的图片切换特效代码,类似旋转木马一样,幻灯图片以三维视觉上下滑动切换,效果很酷炫,兼容IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜 ...

    5. Winform下实现图片切换特效的方法

      本文实例讲述了Winform下实现图片切换特效的方法,是应用程序开发中非常实用的一个功能.分享给大家供大家参考之用.具体方法如下: 本实例源自网络,功能较为齐全.丰富!主要功能代码如下: using ...

    6. [Android实例] app引导页(背景图片切换加各个页面动画效果)(申明:来源于网络)

      [Android实例] app引导页(背景图片切换加各个页面动画效果)(申明:来源于网络) 地址: http://www.eoeandroid.com/thread-918356-1-1.html h ...

    7. 一款基于jquery超炫的图片切换特效

      今天为给大家介绍一款基于jquery超炫的图片切换特效.由百叶窗飞入显示图片.图片消息的时候也是百叶窗渐行渐远.用于图片展示,效果还是非常好,我们一起看下效果图: 在线预览   源码下载 来看下实现的 ...

    8. jQuery plugin : bgStretcher 背景图片切换效果插件

      转自:http://blog.dvxj.com/pandola/jQuery_bgStretcher.html bgStretcher 2011 (Background Stretcher)是一个jQ ...

    9. app引导页(背景图片切换加各个页面动画效果)

      前言:不知不觉中又加班到了10点半,整个启动页面做了一天多的时间,一共有三个页面,每个页面都有动画效果,动画效果调试起来麻烦,既要跟ios统一,又要匹配各种不同的手机,然后产品经理还有可能在中途改需求 ...

    10. ☀【CSS3】背景图片

      CSS3全新的背景图片方案http://www.cnblogs.com/rubylouvre/p/3401125.html

    随机推荐

    1. 无处不在的 Kubernetes,难用的问题解决了吗?

      ​简介: 从第三方的调研数据看,容器和 Kubernetes 已经成为云原生时代主流的选择,但实际落地的时候,却陷入了困境.我们尝试去总结了一些共通点,以及应对方案,也许能为正在落地容器技术的企业提供 ...

    2. 运营也用的起来的数据分析工具:Quick BI即席分析详解

      ​简介: 数据部门是一个容易被投诉的"高危"部门,需求响应慢.数据准确性不高会影响业务的发展. 然而数据分析师每周动辄就有几十个需求在手,无限的加班也无法解决所有问题,到底怎样才能 ...

    3. vue-苟曰的老板不发工资230行原创js代码写个扫雷小游戏

      上gif: 1.开局提示动画 2.游戏中状态提示 3.开挂模式提示 4.计时器 5.游戏模式扫雷成功,蓝色进度条表示当次扫雷的完成度 6.若当次时间小于最佳记录,则更新最佳记录,如果最佳记录小于设置的 ...

    4. SpringBoot3.1.5对应新版本SpringCloud开发(2)-Eureka的负载均衡

      Eureka的负载均衡 负载均衡原理 负载均衡流程 老版本流程介绍 当order-servic发起的请求进入Ribbon后会被LoadBalancerInterceptor负载均衡拦截器拦截,拦截器获 ...

    5. 【简说Python WEB】Flask应用的单元测试

      [简说Python WEB]Flask应用的单元测试 tests/test_basics.py import unittest from flask import current_app from a ...

    6. Ubuntu更新源文件报错:E: 仓库 “http://ppa.launchpad.net/chris-lea/node.js/ubuntu bionic Release” 没有 Release 文件。

      E: 仓库 "http://ppa.launchpad.net/chris-lea/node.js/ubuntu bionic Release" 没有 Release 文件. 一条 ...

    7. uiautomator2使用方法

      一.设备连接 1.usb单设备连接 d = u2.connect() 2.usb多设备连接 d = u2.connect("90bf8faf") # 多台设备填写device即可 ...

    8. installshield 64位系统操作注册表遇到的问题

      最近在研究IS脚本设置jdk环境变量问题,在使用RegDBKeyExist判断注册表中项的时候一直找不到,翻找文档后发现64位的操作系统需要设置 REGDB_OPTIONS. "SOFTWA ...

    9. js数组方法之数组变异方法

      push.pop.unshift.shift.sort.splice.reverse 以上这些方法都会改变原数组并且 这些方法的返回值是值得注意的有时候可以提高工作效率,比如pop方法的返回值是该元素 ...

    10. 2D空间中比较两三角形相交与包含

      在处理UV重叠.CPU的ZFighting检测时会遇到2D空间中的三角形相交问题, 网上普遍是3D空间的相交解法,因此写本文研究下,不过虽然实现了需求, 但用的方法比较暴力. 效果如图: (鼠标拖动区 ...