您好,登錄后才能下訂單哦!
這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)使用jQuery怎么實(shí)現(xiàn)一個(gè)滑塊滑動(dòng)導(dǎo)航效果,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
具體如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>www.jb51.net jquery滑動(dòng)導(dǎo)航</title> <style> *{margin: 0;padding: 0;box-sizing: border-box;-moz-box-sizing: border-box;} body { font: 16px/20px 'Microsoft yahei,微軟雅黑'; color: #AFBBBB; } ul { list-style-type: none; } ul li { float: left; } a { text-decoration: none; color: #AFBBBB; } a:hover { color: #ffffff; cursor: pointer; } .clearfix:before,.clearfix:after { content:""; clear: both; display: table; height: 0; zoom: 1; overflow: hidden; } .nav { width:519px; margin: 0 auto; } .nav ul { background: gray; height: 35px; line-height: 35px; position: relative; padding: 0 5px; } .nav ul li { position: relative; padding: 0 25px; } .nav ul li>a { position: relative; z-index: 100; /*將a元素的z-index設(shè)置比li大,這樣hover效果才不會(huì)無(wú)效*/ } .nav ul li:last-child { width: 98px; height: 90%; position: absolute; z-index: 50; left: 5px; bottom: 0; top: 0; margin: auto; background: rgba(152,206,170,0.5); border-radius: 5px; } </style> </head> <body> <div class="nav"> <ul class="clearfix"> <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >幼兒園</a></li> <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >小學(xué)</a></li> <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >初中</a></li> <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >高中</a></li> <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >大學(xué)</a></li> <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >社會(huì)</a></li> <li class="huadong" id="huaBlock"></li> </ul> </div> <script src="http://cdn.bootcss.com/jquery/2.1.0/jquery.js"></script> <script> $(function(){ $("ul li:not(:last)").hover(function(){ $("#huaBlock").stop(); //停止正在運(yùn)行的動(dòng)畫(huà) var curliWidth=$(this).outerWidth(),curleft=$(this).offset().left-$(this).parent().offset().left; //當(dāng)前l(fā)i的偏移量減去當(dāng)前ul的偏移量就是li距離ul的距離 // alert("curleft:"+curleft); $("#huaBlock").animate({"width":curliWidth,"left":curleft},500); },function(){ $("#huaBlock").stop(); $("#huaBlock").animate({"width":98,"left": 5},200); }); }); </script> </body> </html>
上述就是小編為大家分享的使用jQuery怎么實(shí)現(xiàn)一個(gè)滑塊滑動(dòng)導(dǎo)航效果了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。