1.translate 移动
通过 translate() 方法,元素从其当前位置移动,根据给定的 left(x 坐标) 和 top(y 坐标) 位置参数:
用法:
transform: translate(50px, 100px);
-ms-transform: translate(50px,100px);
-webkit-transform: translate(50px,100px);
-o-transform: translate(50px,100px);
-moz-transform: translate(50px,100px);
2.transform 改变、变形
旋转:rotate() 顺时针旋转给定的角度,允许负值 rotate(30deg) 扭曲:skew() 元素翻转给定的角度,根据给定的水平线(X 轴) 和垂直线(Y 轴)参数:skew(50deg,20deg) 缩放:scale() 放大或缩小,根据给定的宽度(X 轴)和高度(Y 轴)参数: scale(2,4) 移动:translate() 平移,传进 x,y值,代表沿x轴和y轴平移的距离
综合起来使用:transform: 30deg 1.5 50deg 20deg 100px 200px;
3.transition 过渡
允许CSS属性值在一定的时间区间内平滑的过渡,需要事件的触发,例如单击、获取焦点、失去焦点等
transition:property duration timing-function delay;
- transition-property 规定设置过渡效果的 CSS 属性的名称。
- transition-duration 规定完成过渡效果需要多少秒或毫秒。
- transition-timing-function 规定速度效果的速度曲线。
- transition-delay 定义过渡效果何时开始。
<style>
div{
width:100px;
height:100px;
background:blue;
transition:width 2s;
}
div:hover
{
width:300px;
}
</style>
<div></div>
4.animation 动画
语法 animation: name duration timing-function delay iteration-count direction; animation-name 规定需要绑定到选择器的 keyframe 名称. animation-duration 规定完成动画所花费的时间,以秒或毫秒计. animation-timing-function 规定动画的速度曲线. animation-delay 规定在动画开始之前的延迟. animation-iteration-count 规定动画应该播放的次数. animation-direction 规定是否应该轮流反向播放动画.
<!DOCTYPE html>
<html>
<head>
<style>
div
{
width:100px;
height:100px;
background:red;
position:relative;
animation:mymove 5s infinite;
-webkit-animation:mymove 5s infinite; /*Safari and Chrome*/
}
@keyframes mymove
{
from {left:0px;}
to {left:200px;}
}
</style>
</head>
<body>
<div></div>
</body>
</html>