如何使用jQuery技術(shù)開發(fā)ios風(fēng)格的頁面導(dǎo)航菜單
效果圖:


目前市場(chǎng)上越來越流行IOS風(fēng)格的操作系統(tǒng)和導(dǎo)航方式,在今天的jQuery教程中,我們介紹如何生成一個(gè)iphone風(fēng)格的菜單導(dǎo)航。
HTML代碼
我們使用鑲嵌的<li>來生成菜單內(nèi)容,并且包含在<nav>標(biāo)簽中,如下:
<nav> <h1>導(dǎo)航菜單</h1> <ul> <li> <h2>專題教程</h2> <ul> <li> <h3>HTML專題教程</h3> <ul> <li><a >GBin1專題之HTML5教程 - 第一篇:HTML5介紹</a></li> <li><a >GBin1專題之HTML5教程 - 第二篇:HTML5元素</a></li> <li><a >GBin1專題之HTML5教程 - 第三篇:HTML5 Video元素</a></li> <li><a >GBin1專題之HTML5教程 - 第四篇:HTML5 Video Doc</a></li> <li><a >GBin1專題之HTML5教程 - 第五篇:HTML5 Audio元素</a></li> </ul> <li> <h3>GBin1熱點(diǎn)秀</h3> <ul> <li><a >GBin1專題之Web熱點(diǎn)秀#1</a> <li><a >GBin1專題之Web熱點(diǎn)秀#2</a> <li><a >GBin1專題之Web熱點(diǎn)秀#3</a> </ul> </ul>
。。。 。。。
Javascript
使用jQuery來查詢遍歷li,并且生成菜單項(xiàng)目,如下:
$(function(){
var nav = $("nav"),
navTitle = nav.children().first(),
navTitleLabel = navTitle.text(),
mainList = navTitle.next(),
subLevels = mainList.find("ul"),
hiddenClass = "hidden";
nav.addClass("js");
mainList.find("a:last-child").addClass("files");
subLevels.addClass(hiddenClass);
navTitle.wrap($("<div/>")).before($("<a/>", {
href: "#",
className: hiddenClass,
click: function(e){
var $this = $(this),
activeList = subLevels.filter(":visible:last"),
activeListParents = activeList.parents("ul");
navTitle.text($this.text());
if(activeListParents.length > 2)
$this.text(activeListParents.eq(1).prev().text());
else if (activeListParents.length > 1)
$this.text(navTitleLabel)
else
$this.addClass(hiddenClass).empty();
setTimeout(
function(){
activeList.addClass(hiddenClass);
}, slideDuration - 100
);
mainList.css("left", parseInt(mainList.css("left")) + navWidth + "px");
e.preventDefault();
}
}));
subLevels.prev().wrap($("<a/>", {
href:"#",
click: function(e){
var $this = $(this);
backArrow.removeClass(hiddenClass).text(navTitle.text());
navTitle.text($this.text());
$this.next().removeClass(hiddenClass);
mainList.css("left", parseInt(mainList.css("left")) - navWidth + "px");
e.preventDefault();
}
}));
var backArrow = navTitle.prev(),
navWidth = nav.width(),
firstSubLevel = subLevels.eq(0),
docStyle = document.documentElement.style,
slideDuration = 0,
timingRatio = 1000;
if(docStyle.WebkitTransition !== undefined)
slideDuration = parseFloat(
firstSubLevel.css("-webkit-transition-duration")
) * timingRatio;
if(docStyle.MozTransition !== undefined)
slideDuration = parseFloat(
firstSubLevel.css("-moz-transition-duration")
) * timingRatio;
if(docStyle.OTransition !== undefined)
slideDuration = parseFloat(
firstSubLevel.css("-o-transition-duration")
) * timingRatio;
});
CSS
使用圖片來生成頁面頂端的按鈕:
body {
font-size: 14px;
font-family: Arial;
background:#f5f5f8;
}
.js {
position:absolute;
width:320px;
height:480px;
top:50%;
left:50%;
margin:-280px 0 0 -160px;
overflow:hidden;
-webkit-border-radius:5px;
-moz-border-radius:5px;
border-radius:5px;
background:#fff;
-webkit-box-shadow:0 1px 2px rgba(0,0,0,.25);
-moz-box-shadow:0 1px 2px rgba(0,0,0,.25);
box-shadow:0 1px 2px rgba(0,0,0,.25);
}
.js .files {
background-image:none;
}
.js .hidden {
display:none;
}
.js * {
font-size:14px;
font-weight:400;
margin:0;
padding:0;
list-style:none;
}
.js > div {
position:relative;
z-index:1;
height:44px;
text-align:center;
font-size:14px;
line-height:44px;
color:#fff;
text-shadow:0 -1px 0 rgba(0,0,0,.4);
background:#7f94b0;
background:-webkit-gradient(
linear,
0 0,
0 100%,
color-stop(0,#b5c0ce),
color-stop(0.5,#889bb3),
color-stop(0.51,#7f94b0),
color-stop(1,#6d83a1)
);
background:-moz-linear-gradient(
top center,
#b5c0ce,
#889bb3 22px,
#7f94b0 23px,
#6d83a1
);
border-bottom:1px solid #2d3033;
-webkit-border-top-left-radius:5px;
-webkit-border-top-right-radius:5px;
-moz-border-radius-topleft:5px;
-moz-border-radius-topright:5px;
border-top-left-radius:5px;
border-top-right-radius:5px;
}
.js > div a {
height:31px;
top:7px;
left:20px;
font-size:14px;
line-height:31px;
color:#fff;
background:url('../images//center.png');
}
.js > div a, .js > div a:before, .js > div a:after {
position:absolute;
}
.js > div a:before {
left:-13px;
content:url('../images//left.png');
}
.js > div a:after {
right:-10px;
top:0;
content:url('../images//right.png');
}
.js > div a:active {
opacity:.65;
}
.js a {
text-decoration:none;
}
.js ul a {
display:block;
color:#000;
padding:.8em 18px;
border-bottom:1px solid #e0e0e0;
background:url('images/next.png') no-repeat 94% 50%;
}
.js ul a:hover {
background-color:#edf3fe;
}
.js a:focus {
outline:none;
}
.js ul {
position:absolute;
top:0;
padding-top:45px;
width:100%;
-webkit-transition:left .4s ease-out;
-moz-transition:left .4s ease-out;
-o-transition:left .4s ease-out;
}
.js ul {
left:0;
}
.js ul ul {
left:320px;
}
有效果圖,有代碼看起來非常明了,希望大家喜歡。
- iOS 三級(jí)下拉菜單功能實(shí)現(xiàn)
- iOS10 widget實(shí)現(xiàn)3Dtouch 彈出菜單
- iOS下拉選擇菜單簡(jiǎn)單封裝
- iOS實(shí)現(xiàn)簡(jiǎn)單的二級(jí)菜單效果
- IOS中safari下的select下拉菜單文字過長(zhǎng)不換行的解決方法
- IOS代碼筆記之下拉菜單效果
- iOS中長(zhǎng)按調(diào)出菜單組件UIMenuController的使用實(shí)例
- iOS從App跳轉(zhuǎn)至系統(tǒng)設(shè)置菜單各功能項(xiàng)的編寫方法講解
- iOS實(shí)現(xiàn)頂部標(biāo)簽式導(dǎo)航欄及下拉分類菜單
- iOS實(shí)現(xiàn)Pad上菜單彈出界面
相關(guān)文章
jquery實(shí)現(xiàn)未經(jīng)美化的簡(jiǎn)潔TAB菜單效果
這篇文章主要介紹了jquery實(shí)現(xiàn)未經(jīng)美化的簡(jiǎn)潔TAB菜單效果,涉及jquery鼠標(biāo)click事件實(shí)現(xiàn)頁面元素樣式動(dòng)態(tài)變換的功能,需要的朋友可以參考下2015-08-08
jquery中animate的stop()方法作用實(shí)例分析
這篇文章主要介紹了jquery中animate的stop()方法作用,實(shí)例分析了animate的stop()方法在視頻播放代碼中的使用技巧,感興趣的朋友可以對(duì)比分析一下帶stop方法與不帶stop方法運(yùn)行效果的區(qū)別,需要的朋友可以參考下2015-01-01
jQuery validate 中文API 附validate.js中文api手冊(cè)
jQuery validate 中文API 附validate.js中文api手冊(cè)2010-07-07
解析ajaxFileUpload 異步上傳文件簡(jiǎn)單使用
本篇文章主要介紹了ajaxFileUpload 異步上傳文件簡(jiǎn)單使用,jQuery插件AjaxFileUpload可以實(shí)現(xiàn)ajax文件上傳。有興趣的可以了解一下,2016-12-12
輕松學(xué)習(xí)jQuery插件EasyUI EasyUI實(shí)現(xiàn)拖放商品放置購物車
這篇文章主要幫助大家輕松學(xué)習(xí)EasyUI實(shí)現(xiàn)拖放商品放置購物車的功能,購物籃中的物品和價(jià)格也將進(jìn)行更新,感興趣的小伙伴們可以參考一下2015-11-11
jquery中的sortable排序之后的保存狀態(tài)的解決方法
其實(shí)在前年的這個(gè)時(shí)候,我就有用過這個(gè)sortable組件,那時(shí)候搞了個(gè)個(gè)人網(wǎng)站(可惜后來關(guān)了),首頁就用到了這種拖拽的效果。2010-01-01
Jquery 插件學(xué)習(xí)實(shí)例1 插件制作說明與tableUI優(yōu)化
Jquery 插件學(xué)習(xí)實(shí)例1 插件制作說明與tableUI優(yōu)化,需要的朋友可以參考下。2010-04-04
jQuery插件實(shí)現(xiàn)大圖全屏圖片相冊(cè)
這篇文章主要介紹了jQuery插件實(shí)現(xiàn)大圖全屏圖片相冊(cè)的方法和示例,基于jQuery插件jQuery.album.js來實(shí)現(xiàn)的,效果非常不錯(cuò),這里推薦給大家,希望大家能夠喜歡。2015-03-03

