1. HTML部分(难点在于stop()animate自定义动画的位置)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>前端左边滑出导航</title>
<link rel="stylesheet" href="../static/css/style.css">
<link rel="stylesheet" type="text/css" href="../static/font-awesome/css/font-awesome.min.css">
<script src="../static/js/jquery.js"></script>
<script>
$(function(){
$('#nav li').stop().animate({'marginLeft':'-65px'},1000)
$('li').hover(
function(){
$(this).stop().animate({'marginLeft':'-2px'},500)
},
function(){
$(this).stop().animate({'marginLeft':'-65px'},500)
}
)
})
</script>
</head>
<body>
<ul id="nav">
<li class="li1"><span class="fa fa-tags"></span></li>
<li class="li2"><span class="fa fa-address-card"></span></li>
<li class="li3"><span class="fa fa-grav"></span></li>
<li class="li4"><span class="fa fa-user-o"></span></li>
<li class="li5"><span class="fa fa-handshake-o"></span></li>
</ul>
</body>
</html>
2.CSS部分sytle.css
*{margin: 0px;padding: 0px;}
ul{list-style: none;position: fixed;top: 10px;left: 0px;}
#nav li{width: 80px;height: 80px;margin: 10px 0px;border-top-right-radius: 10px;border-bottom-right-radius: 10px;line-height: 80px;text-align: center;}
.li1{background: rgba(77,31,216,0.5);}
.li2{background: rgba(247,3,8,0.5);}
.li3{background: rgba(247,247,3,0.5);}
.li4{background: rgba(44,3,247,0.5);}
.li5{background: rgba(3,247,36,0.5);}
#nav li span {font-weight: 700;font-size: 30px;color:#fff;}