jQuery實現(xiàn)的滑塊滑動導(dǎo)航效果示例
本文實例講述了jQuery實現(xiàn)的滑塊滑動導(dǎo)航效果。分享給大家供大家參考,具體如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>www.fzitv.net jquery滑動導(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效果才不會無效*/
}
.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" >社會</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; //當(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代碼運行工具 http://tools.jb51.net/code/HtmlJsRun測試運行效果如下:

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery切換特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
- 基于jquery實現(xiàn)鼠標(biāo)左右拖動滑塊滑動附源碼下載
- Jquery實現(xiàn)彈性滑塊滑動選擇數(shù)值插件
- jQuery animate(滑塊滑動效果代碼)
- jQuery彈性滑動導(dǎo)航菜單實現(xiàn)思路及代碼
- jQuery實現(xiàn)簡單的滑動導(dǎo)航代碼(移動端)
- jquery實現(xiàn)背景跟隨鼠標(biāo)滑動導(dǎo)航
- jQuery藍(lán)色風(fēng)格滑動導(dǎo)航欄代碼分享
- Jquery網(wǎng)頁內(nèi)滑動緩沖導(dǎo)航的實現(xiàn)代碼
- 基于jquery實現(xiàn)百度新聞導(dǎo)航菜單滑動動畫
相關(guān)文章
input file樣式修改以及圖片預(yù)覽刪除功能詳細(xì)概括(推薦)
這篇文章主要介紹了input file樣式修改以及圖片預(yù)覽刪除功能,input file 按鈕改成自己想要的樣式以及.圖片預(yù)覽功能的實現(xiàn),具體操作步驟大家可查看下文的詳細(xì)講解,感興趣的小伙伴們可以參考一下。2017-08-08
JQuery動態(tài)添加Select的Option元素實現(xiàn)方法
下面小編就為大家?guī)硪黄狫Query動態(tài)添加Select的Option元素實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-08-08
jquery中dom操作和事件的實例學(xué)習(xí)-表單驗證
這個demo的效果是實現(xiàn)用戶輸入時提供實時提醒,并不一定要等到元素失去焦點時才提醒2011-11-11
jQuery之$(document).ready()使用介紹
學(xué)習(xí)jQuery的第一件事是:如果你想要一個事件運行在你的頁面上,你必須在$(document).ready()里調(diào)用這個事件2012-04-04
ASP.NET jQuery 實例8 (動態(tài)添加內(nèi)容到DropDownList)
在web應(yīng)用里,我們經(jīng)常需要通過其他控件的事件觸發(fā)動態(tài)構(gòu)造DropDownList數(shù)據(jù)內(nèi)容。在這節(jié)中,我們將會看到如何實現(xiàn)通過選擇第一個下來框的內(nèi)容來動態(tài)構(gòu)造第二個下拉框的內(nèi)容2012-02-02

