• css3 3d变换和动画——回顾


    1.transform-style 属性指定嵌套原始是怎样在三维空间中呈现。
      语法:transform-style: flat | preserve-3d
          flat 表示所有子元素在2D平面呈现。
          preserve-3d 表示所在元素在3D空间中呈现。
    2.perspective  定义3D元素距视图的距离,以像素计,当为元素定义perspective 属性时,其子元素获得透视效果,而不是元素本身
      语法:perspective: number | none;
          number 元素距离视图的距离,以像素计。
          none 默认值,与0 相同,不设置透明。
    3.perspective-origin   属性定义3D元素所基于的X轴和Y轴,该属性允许您改变3D 元素的底部位置,定义的这个属性,它是一个元素的子元素,透视图,而不是元素本身。

      语法:perspective-origin: x-axis y-axis
        x-axis 定义该视图在x轴上的位置。
        y-axis 定义该视图在y轴上的位置。

    示例:

      <style>
        .box{60px;height:60px;padding:40px;border:2px solid #000;margin:30px auto; -webkit-transform-style:preserve-3d;-webkit-
            perspective:100px;}
        .div{60px;height:60px;background:red; transition:1s;}
        .box:hover .div{-webkit-transform:rotateX(180deg);}
      </style>
      <div class="box">
         <div class="div">111</div>
      </div>

      结果:如图

        

    示例:

      <style>
        .box{60px;height:60px;padding:40px;border:2px solid #000;margin:30px auto; -webkit-
            transform-style:preserve-3d;-webkit-perspective:100px;}
        .div{60px;height:60px;background:red; transition:1s;}
        .box:hover .div{-webkit-transform:rotateY(180deg);}
      </style>
      <div class="box">
        <div class="div">111</div>
      </div>

    结果:如图

        

    示例:

     <style>
        .box{60px;height:60px;padding:40px;border:2px solid #000;margin:30px auto; -webkit-
            transform-style:preserve-3d;-webkit-perspective:100px;}
        .div{60px;height:60px;background:red; transition:1s;}
        .box:hover .div{-webkit-transform:rotateZ(180deg);}
      </style>
      <div class="box">
        <div class="div">111</div>
      </div>

    结果:如图

        

    示例:(正方形)

      <style>
        .wrap{60px;height:60px;padding:20px; border:2px solid #000; margin:100px auto;
            -webkit-perspective:200px; -webkit-transform:scale(2);-webkit-perspective-origin:center center;}
        .box{60px;height:60px;background:red; position:relative; -webkit-transform-style:preserve-3d; transition:2s;
            -webkit-transform-origin:center center -50px;}
        .box div{60px;height:60px; position:absolute; color:#fff;font-size:50px; text-align:center;line-height:60px;}
        .box div:nth-of-type(1){left:0;top:-60px;background:#9C0; -webkit-transform-origin:bottom; -webkit-transform:rotateX(90deg);}
        .box div:nth-of-type(2){left:-60px;top:0px;background:#CF3; -webkit-transform-origin:right; -webkit-transform:rotateY(-90deg);}
        .box div:nth-of-type(3){left:0px;top:0px;background:#CCF;}
        .box div:nth-of-type(4){left:60px;top:0;background:#0C9;-webkit-transform-origin:left;-webkit-transform:rotateY(90deg);}
        .box div:nth-of-type(5){left:0px;top:60px;background:#69C;-webkit-transform-origin:top;-webkit-transform:rotateX(-90deg);}
        .box div:nth-of-type(6){left:0;top:0;background:#F0C;-webkit-transform:translateZ(-60px) rotateX(180deg);}
        .wrap:hover .box{ -webkit-transform:rotateX(180deg);}
      </style>
      <div class="wrap">
        <div class="box">
          <div>1</div>
          <div>2</div>
          <div>3</div>
          <div>4</div>
          <div>5</div>
          <div>6</div>
        </div>
      </div>

    结果:如图

      

    4.animation
        Keyframes 具有其自己的语法规则 ,他的命名是由”@keyframes“ 开头,后面紧接着这个动画的名称 加上一堆花括号。
        对于一个"@keyframes"中的样式规则是由多个百分比构成的,如“0%”到"100%"之间

           @keyframes IDENT {
                from {
                    Properties:Properties value;
                }
                Percentage {
                    Properties:Properties value;
                }
                to {
                    Properties:Properties value;
                }
            }

        或者全部写成百分比的形式:

        @keyframes IDENT {
              0% {
               Properties:Properties value;
            }
            Percentage {
              Properties:Properties value;
            }
            100% {
              Properties:Properties value;
            }
          }

        其中IDENT是一个动画名称,你可以随便取,当然语义化一点更好,

        @-webkit-keyframes 'wobble' {
              0% {
                margin-left: 100px;
                background: green;
              }
              40% {
                margin-left: 150px;
                background: orange;
              }
              60% {
                margin-left: 75px;
                background: blue;
              }
              100% {
                margin-left: 100px;
                background: red;
                }
            }

        元素调用animation属性
           如:

          .demo1 {
                   50px;
                  height: 50px;
                  margin-left: 100px;
                  background: blue;
                  -webkit-animation-name:'wobble';/*动画属性名,也就是我们前面keyframes定义的动画名*/
                  -webkit-animation-duration: 10s;/*动画持续时间*/
                  -webkit-animation-timing-function: ease-in-out; /*动画频率,和transition-timing-function是一样的*/
                  -webkit-animation-delay: 2s;/*动画延迟时间*/
                  -webkit-animation-iteration-count: 10;/*定义循环资料,infinite为无限次*/
                  -webkit-animation-direction: alternate;/*定义动画方式*/
              }

    属性:
    1.animation-name:
            语法:animation-name: none | IDENT[,none | IDENT]*;
            animation-name:是用来定义一个动画的名称,其主要有两个值:IDENT是由Keyframes创建的动画名,
            换句话说此处的IDENT要和Keyframes中的IDENT一致,
            如果不一致,将不能实现任何动画效果;none为默认值,当值为none时,将没有任何动画效果。另外我们这
            个属性跟前面所讲的transition一样,我们可以同时附
            几个animation给一个元素,我们只需要用逗号“,”隔开。
    2.animation-duratiuon
            语法:animation-duration: <time>[,<time>]*
            animation-duration是用来指定元素播放动画所持续的时间长,取值:<time>为数值,单位为s (秒.)其默认值为“0”。
            这个属性跟transition中的transition-duration使用方法是一样的。
    3.animation-timing-function:
            animation-timing-function:是指元素根据时间的推进来改变属性值的变换速率,说得简单点就是动画的播放方式。
            他和transition中的transition-timing-function一样,具有以下六种变换方式:ease;ease-in;ease-in-out;linear;cubic-bezier。
            具体的使用方法大家可以点这里,查看其中transition-timing-function的使用方法。
    4.animation-delay
            语法:animation-delay: <time>[,<time>]*
            animation-delay:是用来指定元素动画开始延迟时间。取值为<time>为数值,单位为s(秒),其默认值也是0。
            这个属性和transition-delayy使用方法是一样的。
     5.animation-iteration-count
            animation-iteration-count:infinite | <number> [, infinite | <number>]*
            animation-iteration-count是用来指定元素播放动画的循环次数,其可以取值<number>为数字,其默认值为“1”;infinite为无限次数循环。
    6.animation-direction
            语法: animation-direction: normal | alternate [, normal | alternate]*
            animation-direction是用来指定元素动画播放的方向,其只有两个值,默认值为normal,如果设置为normal时,
            动画的每次循环都是向前播放;
            另一个值是alternate,他的作用是,动画播放在第偶数次向前播放,第奇数次向反方向播放。
    7.animation-play-state
            语法:animation-play-state:running | paused [, running | paused]*
            animation-play-state主要是用来控制元素动画的播放状态。其主要有两个值,running和paused其中running为默认值。
            他们的作用就类似于我们的音乐播放器一样,可以通过paused将正在播放的动画停下了,也可以通过running将暂停的动画重新播放,
            我们这里的重新播放不一定是从元素动画的开始播放,而是从你暂停的那个位置开始播放。

    示例: 

      <style>
        @-webkit-keyframes anim
            {
             0%{
              100px;
           }
           100%
           {
             200px;
           }
        }
        .box{100px;height:100px;background:red; -webkit-animation:2s anim;}
      </style>
      <div class="box"></div>

    结果:如图

        

    
    

    示例: 

      <style>
        @-webkit-keyframes anim
          {
            0%{
              100px;
              }
            100%
              {
                200px;
              }
          }
        .box{100px;height:100px;background:red; -webkit-animation:2s anim infinite linear;}
      </style>
      <div class="box"></div>

    结果:动画从头到尾的速度是相同的。

    示例:

     <style>
        @-webkit-keyframes anim
          {
            0%{
                100px;
              }
            100%
              {
                200px;
              }
          }
        .box{100px;height:100px;background:red; -webkit-animation:2s anim ease-in infinite;}
      </style>
      <div class="box"></div>

    结果:如图

      

    示例:
     

     <style>
        @-webkit-keyframes move
                {
                  0%{
                      left:0;
                     }
                  100%
                    {
                      left:-500px;
                    }
              }
        #wrap{ 500px;height:100px;border:1px solid #000; position:relative;margin:100px auto; overflow:hidden;}
        #list{ position:absolute;left:0;top:0;margin:0;padding:0; -webkit-animation:5s move infinite linear; 200%;}
        #list li{ list-style:none;98px;height:98px;border:1px solid #fff;background:#000; color:#fff; font:50px/98px Arial; text-align:center; float:left;}
        #wrap:hover #list{ -webkit-animation-play-state:paused;}
      </style>
      <div id="wrap">
        <ul id="list">
           <li>1</li>
           <li>2</li>
           <li>3</li>
           <li>4</li>
           <li>5</li>
           <li>1</li>
           <li>2</li>
           <li>3</li>
           <li>4</li>
           <li>5</li>
        </ul>
      </div>

    结果:循环运动,鼠标悬浮停止。

     5.animation-play-state     规定动画是正在运行还是暂停

        语法:animation-play-state: paused | running

               paused 动画已暂停

              running 动画正在播放

    demo下载https://github.com/ningmengxs/css3.git

  • 相关阅读:
    Pandas速查手册中文版
    MySQL-增删改查
    主从复制-常见问题
    redis-主从复制
    高级数据类型-GEO
    高级数据类型-HyperLogLog
    高级数据类型-bitmaps
    redis-redis.conf基础配置
    删除策略--逐出策略
    删除策略-过期数据
  • 原文地址:https://www.cnblogs.com/nmxs/p/6382437.html
Copyright © 2020-2023  润新知