jQuery實(shí)現(xiàn)的滑塊滑動(dòng)導(dǎo)航效果示例
本文實(shí)例講述了jQuery實(shí)現(xiàn)的滑塊滑動(dòng)導(dǎo)航效果。分享給大家供大家參考,具體如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>www.dbjr.com.cn 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>
使用在線HTML/CSS/JavaScript代碼運(yùn)行工具 http://tools.jb51.net/code/HtmlJsRun測(cè)試運(yùn)行效果如下:
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《jQuery切換特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery常見(jiàn)經(jīng)典特效匯總》、《jQuery動(dòng)畫(huà)與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- 基于jquery實(shí)現(xiàn)鼠標(biāo)左右拖動(dòng)滑塊滑動(dòng)附源碼下載
- Jquery實(shí)現(xiàn)彈性滑塊滑動(dòng)選擇數(shù)值插件
- jQuery animate(滑塊滑動(dòng)效果代碼)
- jQuery彈性滑動(dòng)導(dǎo)航菜單實(shí)現(xiàn)思路及代碼
- jQuery實(shí)現(xiàn)簡(jiǎn)單的滑動(dòng)導(dǎo)航代碼(移動(dòng)端)
- jquery實(shí)現(xiàn)背景跟隨鼠標(biāo)滑動(dòng)導(dǎo)航
- jQuery藍(lán)色風(fēng)格滑動(dòng)導(dǎo)航欄代碼分享
- Jquery網(wǎng)頁(yè)內(nèi)滑動(dòng)緩沖導(dǎo)航的實(shí)現(xiàn)代碼
- 基于jquery實(shí)現(xiàn)百度新聞導(dǎo)航菜單滑動(dòng)動(dòng)畫(huà)
相關(guān)文章
jQuery中的deferred對(duì)象和extend方法詳解
本篇文章主要介紹了jQuery中的deferred對(duì)象和extend方法,具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-05-05jQuery+PHP實(shí)現(xiàn)可編輯表格字段內(nèi)容并實(shí)時(shí)保存
在本例中,我們會(huì)通過(guò)jQuery實(shí)現(xiàn)單擊將一個(gè)文本信息變?yōu)榭删庉嫷谋韱?,你可以?duì)文本內(nèi)容進(jìn)行編輯,然后點(diǎn)擊“確定”按鈕,新的內(nèi)容將發(fā)送到后臺(tái)PHP程序處理,并保存到數(shù)據(jù)庫(kù);當(dāng)點(diǎn)擊“取消”按鈕,則頁(yè)面恢復(fù)到初始狀態(tài),需要的朋友可以參考下2015-10-10jquery創(chuàng)建并行對(duì)象或者合并對(duì)象的實(shí)現(xiàn)代碼
如果有對(duì)象A ,B 現(xiàn)在我想要合并成對(duì)象C 從C里面可以找到A , B 及其子對(duì)象 怎么做2012-10-10JQuery移動(dòng)頁(yè)面開(kāi)發(fā)之屏幕方向改變與滾屏的實(shí)現(xiàn)
這篇文章主要介紹了JQuery移動(dòng)頁(yè)面開(kāi)發(fā)之隨屏幕方向改變與滾屏的實(shí)現(xiàn),通過(guò)相關(guān)兩個(gè)事件的添加來(lái)達(dá)到響應(yīng)移動(dòng)設(shè)備上操作的效果,需要的朋友可以參考下2015-12-12JQuery給元素綁定click事件多次執(zhí)行的解決方法
這篇文章主要介紹了JQuery給元素綁定click事件多次執(zhí)行的解決方法,需要的朋友可以參考下2014-05-05jQuery實(shí)現(xiàn)的類(lèi)似淘寶網(wǎng)站搜索框樣式代碼分享
這篇文章主要介紹了類(lèi)似淘寶網(wǎng)站搜索框樣式實(shí)現(xiàn)代碼,推薦給大家,有需要的小伙伴可以參考下。2015-08-08jQuery使用正則表達(dá)式替換dom元素標(biāo)簽用法示例
這篇文章主要介紹了jQuery使用正則表達(dá)式替換dom元素標(biāo)簽的方法,結(jié)合具體實(shí)例形式分析了jQuery正則替換的操作技巧,需要的朋友可以參考下2017-01-01