侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

纯CSS3绘制打火机动画火焰效果

前端  /  管理员 发布于 7年前   168

本文实例为大家分享了纯CSS3绘制打火机动画火焰效果的具体代码,供大家参考,具体内容如下

主要涉及到了以下属性:

XML/HTML Code复制内容到剪贴板
  1. <span style="font-family:Comic Sans MS;">animation(webkit-animation),   
  2. @keyframes name (@-webkit-keyframes name),   
  3. transform,   
  4. transform-origin,   
  5. transition,   
  6. box-shadow(spread属性),   
  7. text-shadow   
  8. z-index   
  9. linear-gradient。   
  10. radial-gradient   
  11. background-image    
  12. </span>  

 
首先html代码如下:

XML/HTML Code复制内容到剪贴板
  1.  <span style="font-family:Comic Sans MS;"><!DOCTYPE html>  
  2. <html>  
  3.  <head>  
  4.   <meta charset="UTF-8">  
  5.   <title>纯CSS绘制打火机动画火焰特效</title>  
  6.   <link rel="stylesheet" href="css/style.css">  
  7.  </head>  
  8.  <body class="keBody">  
  9.   <h1 class="keTitle">纯CSS3绘制打火机动画火焰特效</h1>  
  10.   <div class="kePublic">  
  11.    <div class="playground">  
  12.     <div class="flame"></div>  
  13.     <div class="lighterBody">  
  14.      <div class="hover">hover me</div>  
  15.     </div>  
  16.     <div class="lid"></div>  
  17.    </div>  
  18.    <div class="clear"></div>  
  19.   </div>    
  20.  </body>  
  21. </html></span>   

style.css文件如下:

CSS Code复制内容到剪贴板
  1. <span style="font-family:Comic Sans MS;">@charset "utf-8";   
  2. body{   
  3.  margin:0;   
  4.  padding:0;   
  5.  color:#333;   
  6.  text-align:center;   
  7.  font:12px "微软雅黑";   
  8. }   
  9. :before,:after{   
  10.  position:absolute;   
  11.  content:"";   
  12. }   
  13. .keBody{   
  14.  background:url(../images/bodyBg.jpg) repeat #333;   
  15. }   
  16. .keTitle{   
  17.  height:100px;   
  18.  line-height:100px;   
  19.  font-size:30px;   
  20.  font-family:'微软雅黑';   
  21.  color:#fff;   
  22.  text-align:center;   
  23.  background:url(../images/bodyBg3.jpg) repeat-x bottombottom left;   
  24.  font-weight:normal;   
  25.  margin-bottom:0;   
  26. }   
  27. .kePublic{   
  28.  background:#cccccc;   
  29.  padding:50px;   
  30. }   
  31. .playground{   
  32.  position:relative;   
  33.  width:140px;   
  34.  height:400px;   
  35.  left:50%;   
  36.  margin-left:-70px;   
  37. }   
  38. .flame{   
  39.    opacity: 0;   
  40.    position: absolute;   
  41.    bottombottom: 60%;   
  42.    left: 42%;   
  43.    width: 14px;   
  44.    height: 70px;   
  45.    background-color: white;   
  46.    border-radius: 100% 100% 0 0;   
  47.    box-shadow: 0 0 20px #FFFEF0, 0 0 20px #FFFEE6, 0 0 20px #fefcc9,  10px -10px 30px #feec85,  -20px -20px 40px #ffae34,  20px -40px 50px #ec760c,  -20px -60px 60px #cd4606,  0 -80px 70px #973716,  10px -90px 80px #451b0e;   
  48.       
  49. }   
  50. .playground:hover .flame {   
  51.  opacity:1;   
  52.  transition:opacity 3s linear;   
  53.  -webkit-animation:flame 1s infinite linear;   
  54.   
  55. }   
  56. .playground:hover .lid{   
  57.  -webkit-animation:lidoff 1s linear;   
  58.  /*把物体动画地从一个地方移动到另一个地方,并让它停留在那里:*/  
  59.  -webkit-animation-fill-mode:forwards;   
  60. }   
  61. .lighterBody{   
  62.  position:absolute;   
  63.  width:140px;   
  64.  height:130px;   
  65.  top:200px;   
  66.  left:0;   
  67.  background-image:linear-gradient(to rightright,#959595 0%,#0d0d0d 46%,#010101 50%,#0a0a0a 53%,   
  68.      #4e4e4e 76%,#383838 87%,#1b1b1b 100%);   
  69.  border-radius:2% 2% 8% 8%;   
  70.  box-shadow:inset 0 0 5px 5px #333;   
  71. }   
  72. .lighterBody:before{   
  73.  width:47px;   
  74.  height:47px;   
  75.  top:-50px;   
  76.  left: 42px;   
  77.  content:"...";   
  78.  color:#e6e6e6;   
  79.  border-radius:6% 6% 0 0;   
  80.  background-image:linear-gradient(to rightright,#f5f5f5 0%,#dbdce2 21%,#b8bac6 49%,#dddfe3 80%,#f5f6f6 100%);   
  81.  font-size:30px;   
  82.  font-weight:bold;   
  83.  letter-spacing:7px;   
  84.  line-height:16px;   
  85.  text-shadow:0 0 5px black;   
  86.  padding-top:3px;   
  87.  padding-left:4px;   
  88. }   
  89. .lighterBody:after{   
  90.  width:33px;   
  91.  height:33px;   
  92.  background-image:radial-gradient(ellipse at center,#7d737d 0%,#0e0e0e 100%);   
  93.  border-radius:100%;   
  94.  top:-33px;   
  95.  left:10px;   
  96.  box-shadow:inset 0 0 1px 2px gray;   
  97. }   
  98. .lid{   
  99.  z-index:2;   
  100.  position:absolute;   
  101.  width:140px;   
  102.  height:75px;   
  103.  top:125px;   
  104.  left:0;   
  105.  background:linear-gradient(to rightright,#959595 0%,#0d0d0d 46%, #010101 50%, #0a0a0a 53%, #4e4e4e 76%, #383838 87%, #1b1b1b 100%);   
  106.  border-radius:8% 8% 2% 2%;   
  107.  box-shadow:inset 0 0 5px 5px #333;   
  108.  /*border-bottom:3px solid #f2f2f2;*/  
  109. }   
  110. .lid:before{   
  111.  width:10px;   
  112.  height:10px;   
  113.  top:70px;   
  114.  left:133px;   
  115.  background-image:radial-gradient(ellipse at center, #959595 0%, #0d0d0d 46%, #010101 50%, #0a0a0a 53%, #4e4e4e 76%, #383838 87%, #1b1b1b 100%);   
  116.  border-radius:100%;   
  117. }   
  118.   
  119. .hover{   
  120.  z-index:1;   
  121.  text-align:center;   
  122.  margin-top:30%;   
  123.  color:rgba(255,255,255,0.9);   
  124.  text-shadow:0 1px 1px rgba(0,0,0,0.8);   
  125.  font: 20px "微软雅黑";   
  126. }   
  127. .hover:before{   
  128.  content:"";   
  129.  z-index:1;   
  130.  width:0;   
  131.  height:0;   
  132.  top:-50px;   
  133.  left:20px;   
  134.  border-bottom:35px solid #f2f2f2;   
  135.  /*border-left:10px solid transparent;*/  
  136. }   
  137. @-webkit-keyframes flame{   
  138.  0%{   
  139.   height:70px;   
  140.   transform:skewY(0deg);   
  141.   border-radius:100% 100% 0 0;   
  142.  }   
  143.  25%{   
  144.   height:60px;   
  145.   transform:skewY(40deg);   
  146.   border-radius:10% 100% 0 0;   
  147.  }   
  148.  60%{   
  149.   height:65px;   
  150.   transform:skewY(-20deg);   
  151.   border-radius:90% 10% 0 0;   
  152.  }   
  153.  70%{   
  154.   height:50px;   
  155.   transform:skewY(10deg);   
  156.   border-radius:10% 100% 0 0;   
  157.  }   
  158.  100%{   
  159.   height:70px;   
  160.   tranform:skewY(0deg);   
  161.  }   
  162. }   
  163. @-webkit-keyframes lidoff{   
  164.  from{   
  165.   transform:rotate(0deg);   
  166.   transform-origin:100% 100%;   
  167.  }   
  168.  to{   
  169.   transform:rotate(130deg);   
  170.   transform-origin:100% 100%;   
  171.  }   
  172. }</span>    

初始照片:

 

动态照片

动画效果主要有两个,一是当鼠标悬停在“hover me”上面时打火机盖子打开的情形,由下面的动画代码实现:

XML/HTML Code复制内容到剪贴板
  1.  <span style="font-family:Comic Sans MS;font-size:12px;">@-webkit-keyframes lidoff{     注意这里要加上-webkit-   
  2.      from{   
  3.           transform:rotate(0deg);   
  4.           transform-origin:100% 100%;   
  5.      }   
  6.      to{   
  7.           transform:rotate(130deg);   
  8.           transform-origin:100% 100%;   
  9.    &nb

  • 上一条:
    浅谈css元素居中
    下一条:
    老生常谈css中float的用法
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 使用 Alpine.js 排序插件对元素进行排序(0个评论)
    • 在js中使用jszip + file-saver实现批量下载OSS文件功能示例(0个评论)
    • 在vue中实现父页面按钮显示子组件中的el-dialog效果(0个评论)
    • 使用mock-server实现模拟接口对接流程步骤(0个评论)
    • vue项目打包程序实现把项目打包成一个exe可执行程序(0个评论)
    • 近期文章
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-10
    • 2017-11
    • 2018-03
    • 2018-04
    • 2018-05
    • 2018-06
    • 2018-09
    • 2018-11
    • 2018-12
    • 2019-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-04
    • 2021-05
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客