一、rotate

2d旋转指的是让元素在2维立体内顺时针旋转或者逆时针旋转

应用步骤:

  1. 给元素增加转换属性 transform
  2. 属性值为 rotate(角度)transform:rotate(30deg) 顺时针方向旋转30度
div{      transform: rotate(0deg);}

三角

div {    position: relative;    width: 249px;    height: 35px;    border: 1px solid #000;}div::after {    content: "";    position: absolute;    top: 8px;    right: 15px;    width: 10px;    height: 10px;    border-right: 1px solid #000;    border-bottom: 1px solid #000;    transform: rotate(45deg);    transition: all 0.2s;}/* 鼠标通过div  外面的三角旋转 */div:hover::after {    transform: rotate(225deg);}

二、设置元素旋转中心点(transform-origin)

  1. transform-origin 根底语法

    transform-origin: x y;
  2. 重要知识点

    • 留神前面的参数 x 和 y 用空格隔开
    • x y 默认旋转的中心点是元素的核心 (50% 50%),等价于 center center
    • 还能够给 x y 设置像素或者方位名词(topbottomleftrightcenter)

旋转核心案例

div {    width: 200px;    height: 200px;    background-color: pink;    margin: 100px auto;    transition: all 1s;    /* 1.能够跟方位名词 */    /* transform-origin: left bottom; */    /* 2. 默认的是 50%  50%  等价于 center  center */    /* 3. 能够是px 像素 */    transform-origin: 50px 50px;}div:hover {    transform: rotate(360deg);}

三、2D 转换之 scale

  1. scale 的作用

    • 用来管制元素的放大与放大
  2. 语法

    transform: scale(x, y)
  3. 常识要点

    • 留神,x 与 y 之间应用逗号进行分隔
    • transform: scale(1, 1): 宽高都放大一倍,相当于没有放大
    • transform: scale(2, 2): 宽和高都放大了二倍
    • transform: scale(2): 如果只写了一个参数,第二个参数就和第一个参数统一
    • transform:scale(0.5, 0.5): 放大
    • scale 最大的劣势:能够设置转换中心点缩放,默认以中心点缩放,而且不影响其余盒子
  4. 代码演示

       div:hover {       /* 留神,数字是倍数的含意,所以不须要加单位 */       /* transform: scale(2, 2) */          /* 实现等比缩放,同时批改宽与高 */       /* transform: scale(2) */          /* 小于 1 就等于缩放*/       transform: scale(0.5, 0.5)   }

四、 2D 转换综合写法以及程序问题

  1. 常识要点

    • 同时应用多个转换,其格局为 transform: translate() rotate() scale()
    • 程序会影响到转换的成果(先旋转会扭转坐标轴方向)
    • 但咱们同时有地位或者其余属性的时候,要将位移放到最后面
  2. 代码演示

    div:hover { transform: translate(200px, 0) rotate(360deg) scale(1.2)}

五、 动画(animation)

  1. 什么是动画

    • 动画是 CSS3 中最具颠覆性的特色之一,可通过设置多个节点来准确的管制一个或者一组动画,从而实现简单的动画成果
  2. 动画的根本应用

    • 先定义动画
    • 在调用定义好的动画
  3. 语法格局(定义动画)

    @keyframes 动画名称 {    0% {        width: 100px;    }    100% {        width: 200px    }}
  1. 语法格局(应用动画)

    div {/* 调用动画 */animation-name: 动画名称; /* 持续时间 */ animation-duration: 持续时间;}
  1. 动画序列

    • 0% 是动画的开始,100 % 是动画的实现,这样的规定就是动画序列
    • 在 @keyframs 中规定某项 CSS 款式,就由创立以后款式逐步改为新款式的动画成果
    • 动画是使元素从一个款式逐步变动为另一个款式的成果,能够扭转任意多的款式任意多的次数
    • 用百分比来规定变动产生的工夫,或用 fromto,等同于 0% 和 100%
  2. 代码演示

    <style>    div {      width: 100px;      height: 100px;      background-color: aquamarine;      animation-name: move;      animation-duration: 0.5s;    }    @keyframes move{      0% {        transform: translate(0px)      }      100% {        transform: translate(500px, 0)      }    }  </style>

六、动画常见属性

  1. 常见的属性

  1. 代码演示

    div {  width: 100px;  height: 100px;  background-color: aquamarine;  /* 动画名称 */  animation-name: move;  /* 动画破费时长 */  animation-duration: 2s;  /* 动画速度曲线 */  animation-timing-function: ease-in-out;  /* 动画期待多长时间执行 */  animation-delay: 2s;  /* 规定动画播放次数 infinite: 有限循环 */  animation-iteration-count: infinite;  /* 是否逆行播放 */  animation-direction: alternate;  /* 动画完结之后的状态 */  animation-fill-mode: forwards;}div:hover {  /* 规定动画是否暂停或者播放 */  animation-play-state: paused;}

七、 动画简写形式

  1. 动画简写形式

    /* animation: 动画名称 持续时间 静止曲线 何时开始 播放次数 是否反方向 起始与完结状态 */animation: name duration timing-function delay iteration-count direction fill-mode
  2. 常识要点

    • 简写属性外面不蕴含 animation-paly-state
    • 暂停动画 animation-paly-state: paused; 常常和鼠标通过等其余配合应用
    • 要想动画走回来,而不是间接调回来:animation-direction: alternate
    • 盒子动画完结后,停在完结地位:animation-fill-mode: forwards
  3. 代码演示

    animation: move 2s linear 1s infinite alternate forwards;

八、速度曲线细节

  1. 速度曲线细节

    • animation-timing-function: 规定动画的速度曲线,默认是ease

  1. 代码演示

    div {  width: 0px;  height: 50px;  line-height: 50px;  white-space: nowrap;  overflow: hidden;  background-color: aquamarine;  animation: move 4s steps(24) forwards;}@keyframes move {  0% {    width: 0px;  }  100% {    width: 480px;  }}