abstrait: <!DOCTYPE html> <html> <head> <title>下滑線跟隨導(dǎo)航</title> <meta charset="utf-8"/> <script typ
<!DOCTYPE html> <html> <head> <title>下滑線跟隨導(dǎo)航</title> <meta charset="utf-8"/> <script type="text/javascript" src="jquery.js"></script> <style type="text/css"> *{ 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: #B3B3B3; font-weight: bold; } .menu{ width:700px;height:32px; position:relative; margin:20px auto; box-shadow: 0 2px 20px #B3B3B3; background: black; border-radius:3px } //.active{ // border-bottom: 3px solid #4b4; // } </style> <script type="text/javascript"> $(function(){ $('li').hover( function(){ $x=parseInt($(this).attr('name'))*100 $('.block').stop().animate({left:$x+'px'},300) }, function(){ $('.block').stop().animate({left:'0px'},300) } ) }) //$(function(){ // var lis=$("li"); // $.each(lis,function(i){ // $(lis[i]).mouseenter(function(e){ // $(".active").removeClass('active'); // $(this).addClass('active'); // }); // }); // }); </script> </head> <body> <div class="menu"> <ul> //<li class="active">首頁(yè)</li> <li name="0">首頁(yè)</li> <li name="1">視頻教程</li> <li name="2">社區(qū)問(wèn)答</li> <li name="3">編程詞典人</li> <li name="4">手冊(cè)下載</li> <li name="5">工具下載</li> <li name="6">菜鳥(niǎo)學(xué)堂</li> </ul> <div class="block" style="z-index:10;width:100px;height:2px;background:#00B33B;position:absolute;top:30px;display:none;"></div> </div> </body> </html>
主要使用的是hover事件,以及animate方法與stop方法
animate用于執(zhí)行動(dòng)畫;animate(內(nèi)部定義動(dòng)畫的屬性方法)
stop()用于清除動(dòng)畫效果;
$(ele).hover(function(){
// 鼠標(biāo)移入時(shí)要執(zhí)行的內(nèi)容
}, function(){
// 鼠標(biāo)移出時(shí)要執(zhí)行的內(nèi)容
})
Professeur correcteur:滅絕師太Temps de correction:2018-12-07 14:05:29
Résumé du professeur:完成的不錯(cuò),條理清楚,知識(shí)點(diǎn)理解的較好!繼續(xù)加油!