サマリー:<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>下拉導(dǎo)航</title><script type="text/javascript" src="../jquery-3.3.1.js"
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>下拉導(dǎo)航</title>
<script type="text/javascript" src="../jquery-3.3.1.js"></script>
<style type="text/css">
*{padding:0;margin:0;}
.menu{
height: 40px;
width: 300px;
background:pink;
margin:0px auto;
position: relative;
top:20px;
}
ul li{
list-style: none;
float:left;
text-align: center;
width: 98px;
height: 38px;
line-height: 40px;
border: 1px solid #ccc;
}
.ha{width: 100px;height: 2px;background: blue;position: absolute;top:40px;}
</style>
<script type="text/javascript">
$(function(){
$('li').hover(function(){
$x=parseInt($(this).attr('name'))*100//最重要的一步獲取x數(shù)
$('.ha').stop().animate({left:$x+'px'},100)
},
function(){
$('.ha').stop().animate({left:'0px'},100)}
)
})
</script>
</head>
<body>
<div class="menu">
<ul>
<li name='0'>wo是紅色</li>
<li name='1'>wo是藍(lán)色</li>
<li name='2'>wo是黃色</li>
</ul>
<div class="ha"></div>
</div>
</body>
</html>
添削の先生:天蓬老師添削時間:2018-11-21 09:18:51
先生のまとめ:動畫實現(xiàn)的方案有很多,這是一種,還有,自定義動畫的參數(shù)很多,最終效果,僅受限于你的想象力