abstrak: 要使下滑線跟隨導(dǎo)航,,需在jQuery中設(shè)置一個(gè)相關(guān)功能的函數(shù),使鼠標(biāo)移動(dòng)‘li’時(shí)找到相關(guān)的name值并生成自定義動(dòng)畫,再在之后設(shè)置一函數(shù)使鼠標(biāo)不在‘li’標(biāo)簽時(shí)默認(rèn)在第一個(gè)標(biāo)簽之下。完整代碼如下: <!DOCTYPE html> <html> <head>  
要使下滑線跟隨導(dǎo)航,,需在jQuery中設(shè)置一個(gè)相關(guān)功能的函數(shù),使鼠標(biāo)移動(dòng)‘li’時(shí)找到相關(guān)的name值并生成自定義動(dòng)畫,再在之后設(shè)置一函數(shù)使鼠標(biāo)不在‘li’標(biāo)簽時(shí)默認(rèn)在第一個(gè)標(biāo)簽之下。
完整代碼如下:
<!DOCTYPE html> <html> <head> <title>下滑線跟隨導(dǎo)航</title> <meta charset="utf-8"/> <script type="text/javascript" src="jquery-3.3.1.js"></script> <style type="text/css"> *{padding:0;margin:0;} ul {list-style: none;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;font-family: 宋體;} .menu{width:500px;position:relative;margin:20px auto;height:32px;box-shadow: 10px 10px 100px #000;background: #9C44A8;border-radius:3px } </style> <script type="text/javascript"> $(function(){ $('li').hover( function(){ $x=parseInt($(this).attr('name'))*100 $('.box').stop().animate({left:$x+'px'},250) }, function(){ $('.box').stop().animate({left:'0px'},250) } ) }) </script> </head> <body> <div class="menu"> <ul> <li name="0">詹姆斯</li> <li name="1">濃眉</li> <li name="2">庫(kù)茲馬</li> <li name="3">球哥</li> <li name="4">英格拉姆</li> </ul> <div class="box" style="z-index:10;width:100px;height:2px;background:#000;position:absolute;top:30px;"></div> </div> </body> </html>
Guru membetulkan:天蓬老師Masa pembetulan:2019-02-20 15:42:07
Rumusan guru:<style type="text/css">, 里面的type屬性, 下次不要寫了,沒必要