您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關使用jQuery怎么實現一個滑塊滑動導航效果,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
具體如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>www.jb51.net jquery滑動導航</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設置比li大,這樣hover效果才不會無效*/ } .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" >小學</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" >大學</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 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(); //停止正在運行的動畫 var curliWidth=$(this).outerWidth(),curleft=$(this).offset().left-$(this).parent().offset().left; //當前li的偏移量減去當前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怎么實現一個滑塊滑動導航效果了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。