2d旋转指的是让元素在2维平面内顺时针旋转或者逆时针旋转
使用步骤:
transform
rotate(角度)
如 transform:rotate(30deg)
顺时针方向旋转30度div{
transform: rotate(0deg);
}
transform-origin
基础语法transform-origin: x y;
center
center
top
、bottom
、left
、right
、center
)2D
转换之 scale
2D
转换综合写法以及顺序问题transform: translate() rotate() scale()
div:hover {
transform: translate(200px, 0) rotate(360deg) scale(1.2)
}
div {
/* 调用动画 */
animation-name: 动画名称;
/* 持续时间 */
animation-duration: 持续时间;
}
/* 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
background-color: #ccc;
}
div {
position: absolute;
width: 200px;
height: 100px;
background: url(media/bear.png) no-repeat;
/* 我们元素可以添加多个动画, 用逗号分隔 */
animation: bear .4s steps(8) infinite, move 3s forwards;
}
@keyframes bear {
0% {
background-position: 0 0;
}
100% {
background-position: -1600px 0;
}
}
@keyframes move {
0% {
left: 0;
}
100% {
left: 50%;
/* margin-left: -100px; */
transform: translateX(-50%);
}
}
</style>
</head>
<body>
<div></div>
</body>
</html>