示例1(平移动画):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>平移动画</title>
<style type="text/css">
ul{
list-style: none;
}
ul li{
float: left;
}
ul li a{
width: 80px;
height: 35px;
display: inline-block;
margin-left: 10px;
background-color: #F7AE66;
color: white;
font-family: "微软雅黑";
line-height: 35px;
text-align: center;
text-decoration: none;
border-radius: 7px; /*圆角矩形*/
}
ul li a:hover{
background-color: red;
transform: translateY(5px);
/* Y方向下移5px 动画 */
}
</style>
</head>
<body>
<ul>
<li><a href="#">服装城</a></li>
<li><a href="#">美妆馆</a></li>
<li><a href="#">超市</a></li>
<li><a href="#">全球购</a></li>
<li><a href="#">闪购</a></li>
<li><a href="#">团购</a></li>
<li><a href="#">拍卖</a></li>
<li><a href="#">金融</a></li>
</ul>
</body>
</html>
示例2(缩放动画):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>缩放动画</title>
<style type="text/css">
ul{
list-style: none;
}
ul li{
float: left;
}
ul li a{
width: 80px;
height: 35px;
display: inline-block;
margin-left: 10px;
background-color: #F7AE66;
color: white;
font-family: "微软雅黑";
line-height: 35px;
text-align: center;
text-decoration: none;
border-radius: 7px;
}
ul li a:hover{
background-color: red;
transform: scale(1.3);
/*放大1.3倍动画*/
}
</style>
</head>
<body>
<ul>
<li><a href="#">服装城</a></li>
<li><a href="#">美妆馆</a></li>
<li><a href="#">超市</a></li>
<li><a href="#">全球购</a></li>
<li><a href="#">闪购</a></li>
<li><a href="#">团购</a></li>
<li><a href="#">拍卖</a></li>
<li><a href="#">金融</a></li>
</ul>
</body>
</html>
示例3(倾斜动画):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>倾斜动画</title>
<style type="text/css">
ul{
list-style: none;
}
ul li{
float: left;
}
ul li a{
width: 80px;
height: 35px;
display: inline-block;
margin-left: 10px;
background-color: #F7AE66;
color: white;
font-family: "微软雅黑";
line-height: 35px;
text-align: center;
text-decoration: none;
border-radius: 7px;
}
ul li a:hover{
background-color: red;
transform: skew(10deg,-10deg);
/*x方向向右倾斜,y方向向上倾斜动画*/
}
</style>
</head>
<body>
<ul>
<li><a href="#">服装城</a></li>
<li><a href="#">美妆馆</a></li>
<li><a href="#">超市</a></li>
<li><a href="#">全球购</a></li>
<li><a href="#">闪购</a></li>
<li><a href="#">团购</a></li>
<li><a href="#">拍卖</a></li>
<li><a href="#">金融</a></li>
</ul>
</body>
</html>
示例4(旋转按钮动画):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>旋转按钮</title>
<style type="text/css">
div img{
margin-left: 30px;
transition: all 1s ease-in-out;
}
div img:hover{
transform: rotate(360deg) scale(1.2);
/*旋转360度,放大1.2倍动画*/
}
</style>
</head>
<body>
<div>
<img src="img/delicious.png" width="64" height="64" />
<img src="img/facebook.png" width="64" height="64" />
<img src="img/rss.png" width="64" height="64" />
<img src="img/twitter.png" width="64" height="64" />
<img src="img/yahoo.png" width="64" height="64" />
</div>
</body>
</html>
示例5(自定义动画 @keyframes):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>animation</title>
<style type="text/css">
div{
width: 242px;
height: 219px;
animation: mya 2s linear infinite;
/*liner 线性速度 infinite 循环播放*/
}
@keyframes mya{
0%{
background: url(img/loading_f03.png);
background-size: cover;
}
15%{
background: url(img/loading_f04.png);
background-size: cover;
}
30%{
background: url(img/loading_f05.png);
background-size: cover;
}
45%{
background: url(img/loading_f06.png);
background-size: cover;
}
60%{
background: url(img/loading_f07.png);
background-size: cover;
}
75%{
background: url(img/loading_f08.png);
background-size: cover;
}
90%{
background: url(img/loading_f09.png);
background-size: cover;
}
100%{
background: url(img/loading_f10.png);
background-size: cover;
}
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
示例6(导航过渡动画):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>导航过渡菜单</title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
ul{
margin: 50px 0px 0px 0px;
list-style: none;
border-bottom: 10px solid green;
width: 100%;
height: 30px;
padding-left: 200px;
}
ul li{
float: left;
}
ul li a{
display: inline-block;
width: 80px;
height: 30px;
text-align: center;
line-height: 30px;
background-color: #CCCCCC;
font-size: 13px;
font-family: "微软雅黑";
text-decoration: none;
color: black;
transition: width 0.5s linear;
/*宽度动画 持续0.5s 线性*/
margin-left: 2px;
}
ul li a:hover{
color: white;
background-color: #9ACD32;
width: 100px;
}
</style>
</head>
<body>
<ul class="nav">
<li>
<a class="on" href="#">首 页</a>
</li>
<li>
<a href="#">关于我们</a>
</li>
<li>
<a href="#">产品展示</a>
</li>
<li>
<a href="#">售后服务</a>
</li>
<li>
<a href="#">联系我们</a>
</li>
</ul>
</body>
</html>
示例7(京东过渡动画):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>京东过渡效果 </title>
<style>
a {
float: left;
width: 183px;
height: 130px;
overflow: hidden;
margin: 10px;
}
img {
width: 193px;
height: 130px;
transition: margin-left 0.4s;
/*过渡动画为左外边距 持续0.4s*/
}
a:hover img {
margin-left: -10px;
}
</style>
</head>
<body>
<div>
<a href="#"><img src="img/1.jpg" alt=""></a>
<a href="#"><img src="img/2.jpg" alt=""></a>
<a href="#"><img src="img/3.jpg" alt=""></a>
</div>
</body>
</html>