本文案例为大伙儿共享了纯CSS3绘图点火机动漫火焰实际效果的实际编码,供大伙儿参照,实际內容以下
关键涉及到到了下列特性:
XML/HTML Code拷贝內容到剪贴板
- <span style="font-family:Comic Sans MS;">animation(webkit-animation),
- @keyframes name (@-webkit-keyframes name),
- transform,
- transform-origin,
- transition,
- box-shadow(spread特性),
- text-shadow
- z-index
- linear-gradient。
- radial-gradient
- background-image
- </span>
最先html编码以下:
XML/HTML Code拷贝內容到剪贴板
- <span style="font-family:Comic Sans MS;"><!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF⑻">
- <title>纯CSS绘图点火机动漫火焰殊效</title>
- <link rel="stylesheet" href="css/style.css">
- </head>
- <body class="keBody">
- <h1 class="keTitle">纯CSS3绘图点火机动漫火焰殊效</h1>
- <div class="kePublic">
- <div class="playground">
- <div class="flame"></div>
- <div class="lighterBody">
- <div class="hover">hover me</div>
- </div>
- <div class="lid"></div>
- </div>
- <div class="clear"></div>
- </div>
- </body>
- </html></span>
style.css文档以下:
CSS Code拷贝內容到剪贴板
- <span style="font-family:Comic Sans MS;">@charset "utf⑻";
- body{
- margin:0;
- padding:0;
- color:#333;
- text-align:center;
- font:12px "微软雅黑";
- }
- :before,:after{
- position:absolute;
- content:"";
- }
- .keBody{
- background:url(../images/bodyBg.jpg) repeat #333;
- }
- .keTitle{
- height:100px;
- line-height:100px;
- font-size:30px;
- font-family:'微软雅黑';
- color:#fff;
- text-align:center;
- background:url(../images/bodyBg3.jpg) repeat-x bottombottom left;
- font-weight:normal;
- margin-bottom:0;
- }
- .kePublic{
- background:#cccccc;
- padding:50px;
- }
- .playground{
- position:relative;
- width:140px;
- height:400px;
- left:50%;
- margin-left:-70px;
- }
- .flame{
- opacity: 0;
- position: absolute;
- bottombottom: 60%;
- left: 42%;
- width: 14px;
- height: 70px;
- background-color: white;
- border-radius: 100% 100% 0 0;
- 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;
-
- }
- .playground:hover .flame {
- opacity:1;
- transition:opacity 3s linear;
- -webkit-animation:flame 1s infinite linear;
-
- }
- .playground:hover .lid{
- -webkit-animation:lidoff 1s linear;
-
- -webkit-animation-fill-mode:forwards;
- }
- .lighterBody{
- position:absolute;
- width:140px;
- height:130px;
- top:200px;
- left:0;
- background-image:linear-gradient(to rightright,#959595 0%,#0d0d0d 46%,#010101 50%,#0a0a0a 53%,
- #4e4e4e 76%,#383838 87%,#1b1b1b 100%);
- border-radius:2% 2% 8% 8%;
- box-shadow:inset 0 0 5px 5px #333;
- }
- .lighterBody:before{
- width:47px;
- height:47px;
- top:-50px;
- left: 42px;
- content:"...";
- color:#e6e6e6;
- border-radius:6% 6% 0 0;
- background-image:linear-gradient(to rightright,#f5f5f5 0%,#dbdce2 21%,#b8bac6 49%,#dddfe3 80%,#f5f6f6 100%);
- font-size:30px;
- font-weight:bold;
- letter-spacing:7px;
- line-height:16px;
- text-shadow:0 0 5px black;
- padding-top:3px;
- padding-left:4px;
- }
- .lighterBody:after{
- width:33px;
- height:33px;
- background-image:radial-gradient(ellipse at center,#7d737d 0%,#0e0e0e 100%);
- border-radius:100%;
- top:-33px;
- left:10px;
- box-shadow:inset 0 0 1px 2px gray;
- }
- .lid{
- z-index:2;
- position:absolute;
- width:140px;
- height:75px;
- top:125px;
- left:0;
- background:linear-gradient(to rightright,#959595 0%,#0d0d0d 46%, #010101 50%, #0a0a0a 53%, #4e4e4e 76%, #383838 87%, #1b1b1b 100%);
- border-radius:8% 8% 2% 2%;
- box-shadow:inset 0 0 5px 5px #333;
-
- }
- .lid:before{
- width:10px;
- height:10px;
- top:70px;
- left:133px;
- background-image:radial-gradient(ellipse at center, #959595 0%, #0d0d0d 46%, #010101 50%, #0a0a0a 53%, #4e4e4e 76%, #383838 87%, #1b1b1b 100%);
- border-radius:100%;
- }
-
- .hover{
- z-index:1;
- text-align:center;
- margin-top:30%;
- color:rgba(255,255,255,0.9);
- text-shadow:0 1px 1px rgba(0,0,0,0.8);
- font: 20px "微软雅黑";
- }
- .hover:before{
- content:"";
- z-index:1;
- width:0;
- height:0;
- top:-50px;
- left:20px;
- border-bottom:35px solid #f2f2f2;
-
- }
- @-webkit-keyframes flame{
- 0%{
- height:70px;
- transform:skewY(0deg);
- border-radius:100% 100% 0 0;
- }
- 25%{
- height:60px;
- transform:skewY(40deg);
- border-radius:10% 100% 0 0;
- }
- 60%{
- height:65px;
- transform:skewY(⑵0deg);
- border-radius:90% 10% 0 0;
- }
- 70%{
- height:50px;
- transform:skewY(10deg);
- border-radius:10% 100% 0 0;
- }
- 100%{
- height:70px;
- tranform:skewY(0deg);
- }
- }
- @-webkit-keyframes lidoff{
- from{
- transform:rotate(0deg);
- transform-origin:100% 100%;
- }
- to{
- transform:rotate(130deg);
- transform-origin:100% 100%;
- }
- }</span>
原始相片:
动态性相片
动漫实际效果关键有两个,1是当电脑鼠标悬停在“hover me”上面时点火机盖子开启的情况,由下面的动漫编码完成:
XML/HTML Code拷贝內容到剪贴板
- <span style="font-family:Comic Sans MS;font-size:12px;">@-webkit-keyframes lidoff{ 留意这里要再加-webkit-
- from{
- transform:rotate(0deg);
- transform-origin:100% 100%;
- }
- to{
- transform:rotate(130deg);
- transform-origin:100% 100%;
- }
- }
- </span>
第2个动漫是烛炬灯光效果实际效果的完成:烛炬由按自变量是由transition:opacity 3s linear; 完成的,
烛炬灯光效果的随风晃动实际效果是由下面的编码完成的:
XML/HTML Code拷贝內容到剪贴板
- <span style="font-family:Comic Sans MS;font-size:12px;">@-webkit-keyframes lidoff{
- from{
- transform:rotate(0deg);
- transform-origin:100% 100%;
- }
- to{
- transform:rotate(130deg);
- transform-origin:100% 100%;
- }
- </span>
将点火机盖与躯干分离出来的实际效果是由:box-shadow:inset 0 0 5px 5px #333; 关键是这里的inset(留意不必写变成insert)完成的。
当点火机开启时出現的圆球和白色的小正方形,是由:after :before 相互配合z-index完成的实际效果。
下面来详细介绍根据这个事例我的学到的几个特性必须留意的地区。
transform-origin: 默认设置的原始部位是图象的管理中心,100% 100%非常于 right bottom. 0% 0%非常于 left top.
before 和:after : 引入的內容是相关联的总体目标元素的字子元素,但它会被置于这个元素任何內容的“前” 或"后"。插进的內容在网页页面的源代码里是看看不到的,只能在css里看见。另外插进的元素在默认设置状况是内联元素。因而,以便给插进的元素授予高宽比、填充、边距这些,一般务必显示信息的界定1个块级元素(display:block)。
另外,尽管将会不容易插进任何內容,可是content务必写上,假如不插进任何內容,那末content写成 content:"";
IE6和IE7兼容问题这两个为元素
伪元素(双冒号),css3中的伪类是(单冒号)
animation-fill-mode: none|forwards|backwards|both|initial|inherit;
要求当动漫不播发时(当动漫进行时,或当动漫有1个延迟时间未刚开始播发时),要运用到元素的款式。
background-image:处理了div只能设定1个情况的难题,使1个div能够设定好几个情况照片。
box-shadow:1个常常被忘却的主要参数--spread(拓展黑影半径),这个以前被忘却的spread更改黑影的尺寸---其值能够是正负值,假如值为正,则全部黑影都延展扩张,反之是负值,则变小。有了这个主要参数后可使用box-shadow像photoshop中的黑影工作中1样,制做单侧黑影实际效果。这里留意1点,这个拓展黑影值必须和黑影模糊不清半径相互配合应用,1般状况是“拓展黑影半径1般设定为和模糊不清半径尺寸,并去其负值”
以上便是本文的所有內容,期待对大伙儿的学习培训有一定的协助,也期待大伙儿多多适用脚本制作之家。