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.dhdzp.com 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)容感興趣的讀者可查看本站專題:《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)文章
input file樣式修改以及圖片預(yù)覽刪除功能詳細(xì)概括(推薦)
這篇文章主要介紹了input file樣式修改以及圖片預(yù)覽刪除功能,input file 按鈕改成自己想要的樣式以及.圖片預(yù)覽功能的實(shí)現(xiàn),具體操作步驟大家可查看下文的詳細(xì)講解,感興趣的小伙伴們可以參考一下。2017-08-08
JQuery動(dòng)態(tài)添加Select的Option元素實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇JQuery動(dòng)態(tài)添加Select的Option元素實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08
jquery animate圖片模向滑動(dòng)示例代碼
jquery animate() 用于創(chuàng)建自定義動(dòng)畫(huà)的函數(shù)。這個(gè)函數(shù)的關(guān)鍵在于指定動(dòng)畫(huà)形式及結(jié)果樣式屬性對(duì)象。2011-01-01
jquery中dom操作和事件的實(shí)例學(xué)習(xí)-表單驗(yàn)證
這個(gè)demo的效果是實(shí)現(xiàn)用戶輸入時(shí)提供實(shí)時(shí)提醒,并不一定要等到元素失去焦點(diǎn)時(shí)才提醒2011-11-11
jQuery之$(document).ready()使用介紹
學(xué)習(xí)jQuery的第一件事是:如果你想要一個(gè)事件運(yùn)行在你的頁(yè)面上,你必須在$(document).ready()里調(diào)用這個(gè)事件2012-04-04
ASP.NET jQuery 實(shí)例8 (動(dòng)態(tài)添加內(nèi)容到DropDownList)
在web應(yīng)用里,我們經(jīng)常需要通過(guò)其他控件的事件觸發(fā)動(dòng)態(tài)構(gòu)造DropDownList數(shù)據(jù)內(nèi)容。在這節(jié)中,我們將會(huì)看到如何實(shí)現(xiàn)通過(guò)選擇第一個(gè)下來(lái)框的內(nèi)容來(lái)動(dòng)態(tài)構(gòu)造第二個(gè)下拉框的內(nèi)容2012-02-02
jQuery禁用鍵盤(pán)后退屏蔽F5刷新及禁用右鍵單擊
這篇文章主要介紹了jQuery禁用鍵盤(pán)后退、屏蔽F5刷新、禁用右鍵單擊功能等快捷方法,感興趣的小伙伴們可以參考一下2016-01-01

