下划线跟随导航作业
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.0.0/jquery.min.js"></script>
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
.nav {
width: 600px;
height: 35px;
background-color: #000;
color: #fff;
line-height: 35px;
margin: 0 auto;
position: relative;
}
.nav ul {
list-style: none;
width: 600px;
height: 35px;
}
.nav ul li {
float: left;
width: 120px;
height: 35px;
text-align: center;
cursor: pointer;
}
.block {
width: 120px;
height: 2px;
background-color: #00c1de;
position: absolute;
top: 35px;
}
</style>
</head>
<body>
<script type="text/javascript">
$(function () {
$('li').hover(
function (){
$x = parseInt($(this).attr('name'))*120
$('.block').stop().animate({left:$x+'px'},500)
},function () {
$('.block').stop().animate({left:'0px'},500)
}
)
})
</script>
<div class="nav">
<ul>
<li name="0">html</li>
<li name="1">css</li>
<li name="2">JavaScript</li>
<li name="3">jQuery</li>
<li name="4">PHP</li>
</ul>
<div class="block"></div>
</div>
</body>
</html>
jQuery也学习完了,越来越发现逻辑和设计的重要性了,不懂设计导航色彩都不会搭配,没有逻辑上下层关系分不清