2d旋转指的是让元素在2维平面内顺时针旋转或者逆时针旋转
使用步骤:css
transform
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
基础语法动画
transform-origin: x y;
重要知识点spa
center
center
top
、bottom
、left
、right
、center
)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
scale
的做用code
语法orm
transform: scale(x, y)
知识要点animation
transform: scale(1, 1)
: 宽高都放大一倍,至关于没有放大transform: scale(2, 2)
: 宽和高都放大了二倍transform: scale(2)
: 若是只写了一个参数,第二个参数就和第一个参数一致transform:scale(0.5, 0.5)
: 缩小scale
最大的优点:能够设置转换中心点缩放,默认以中心点缩放,并且不影响其余盒子代码演示it
div:hover { /* 注意,数字是倍数的含义,因此不须要加单位 */ /* transform: scale(2, 2) */ /* 实现等比缩放,同时修改宽与高 */ /* transform: scale(2) */ /* 小于 1 就等于缩放*/ transform: scale(0.5, 0.5) }
2D
转换综合写法以及顺序问题知识要点io
transform: translate() rotate() scale()
代码演示function
div:hover { transform: translate(200px, 0) rotate(360deg) scale(1.2) }
什么是动画form
CSS3
中最具颠覆性的特征之一,可经过设置多个节点来精确的控制一个或者一组动画,从而实现复杂的动画效果动画的基本使用
语法格式(定义动画)
@keyframes 动画名称 { 0% { width: 100px; } 100% { width: 200px } }
语法格式(使用动画)
div { /* 调用动画 */ animation-name: 动画名称; /* 持续时间 */ animation-duration: 持续时间; }
动画序列
from
和 to
,等同于 0% 和 100%代码演示
<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>
代码演示
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; }
动画简写方式
/* animation: 动画名称 持续时间 运动曲线 什么时候开始 播放次数 是否反方向 起始与结束状态 */ animation: name duration timing-function delay iteration-count direction fill-mode
知识要点
animation-paly-state
animation-paly-state: paused
; 常常和鼠标通过等其余配合使用animation-direction: alternate
animation-fill-mode: forwards
代码演示
animation: move 2s linear 1s infinite alternate forwards;
速度曲线细节
animation-timing-function
: 规定动画的速度曲线,默认是ease
代码演示
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; } }