CSS实现动画的方式(2种)
第一种:transition + transform
transition:设置样式的属性值是如何从一种状态过渡到另一种状态的
transform:主要应用于元素的2D或者3D转换,可以用来设置元素的形状改变。例如rotate(旋转),scale(缩放),skew(扭曲),translate(平移)
div:hover {
transition: 2s;
transform: translateX(100px);
}
第二种:animation + keyfaram
<!DOCTYPE html>
<html>
<head>
<style>
div
{
width:100px;
height:100px;
background:red;
position:relative;
animation:myfirst 5s;
-moz-animation:myfirst 5s; /* Firefox */
-webkit-animation:myfirst 5s; /* Safari and Chrome */
-o-animation:myfirst 5s; /* Opera */
}
@keyframes myfirst
{
0% {background:red; left:0px; top:0px;}
25% {background:yellow; left:200px; top:0px;}
50% {background:blue; left:200px; top:200px;}
75% {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}
@-moz-keyframes myfirst /* Firefox */
{/* 内容同上 */}
@-webkit-keyframes myfirst /* Safari and Chrome */
{/* 内容同上 */}
@-o-keyframes myfirst /* Opera */
{/* 内容同上 */}
</style>
</head>
<body>
<div></div>
</body>
</html>
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。