abstrak:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>下劃線(xiàn)跟隨導(dǎo)航欄</title> <script type="text/javascript" src="jqu
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>下劃線(xiàn)跟隨導(dǎo)航欄</title> <script type="text/javascript" src="jquery.js"></script> <style type="text/css"> /* *{margin:0;padding:0;} div{width: 100%;height: 50px;background-color: #ccc;} nav{width:500px;margin:0 auto;} ul{list-style: none;} li{float: left;line-height: 50px;width: 100px;font-size: 14px;color: #13D1BE;cursor:pointer;} ul div{width: 100px;height: 2px;border: 1px solid red;background:#fff;position:absolute;top:30px;z-index:10;}*/ *{padding:0;margin:0;} ul {list-style: none;z-index:20;position:relative;font-size: 15px;} li {float:left;cursor:pointer;width:100px;height: 30px;text-align:center;line-height:30px;color: #fff;font-weight: bold;} .one{width:500px;position:relative;margin:100px auto;height:32px;box-shadow: 0 2px 20px #000;background: #AF3434;border-radius:3px } .two{z-index:10;width:100px;height:2px;background:#fff;position:absolute;top:30px;} </style> <script type="text/javascript"> $(document).ready(function(){ $('li').hover(function(){ $i=parseInt($(this).attr('name'))*100 $('.two').stop().animate({left:$i+'px'},400) },function(){ $('.two').stop().animate({left:'0px'},300) }) }) </script> </head> <body> <div> <nav> <ul> <li name="0">我的QQ</li> <li name="1">我的微信</li> <li name="2">我的微博</li> <li name="3">我的新浪</li> <li name="4">我的陌陌</li> </ul> <div></div> </nav> </div> </body> </html>
筆記
parseInt() 函數(shù)可解析一個(gè)字符串,并返回一個(gè)整數(shù)
attr() 方法設(shè)置或返回被選元素的屬性值
思路
通過(guò)獲取到li標(biāo)簽的name值,然后通過(guò)paseInt()函數(shù)來(lái)設(shè)置想要下滑線(xiàn)移動(dòng)的距離,接著通過(guò)hover()函數(shù)來(lái)
使鼠標(biāo)移動(dòng)到那個(gè)li標(biāo)簽上面,就使移動(dòng)相對(duì)應(yīng)的距離.
Guru membetulkan:韋小寶Masa pembetulan:2019-03-12 09:16:38
Rumusan guru:寫(xiě)的很不錯(cuò) 效果也是很好看的 總結(jié)的也很完整 在寫(xiě)項(xiàng)目之前只要把自己的項(xiàng)目思路弄清楚寫(xiě)起來(lái)就簡(jiǎn)單了 課后要記得多去練習(xí)