使用jQuery开发iOS风格的页面导航菜单
iOS风格的操作系统和导航方式现在越来越流行,在今天的jQuery教程中,我们将介绍如何生成一个iphone风格的菜单导航。
HTML代码
我们使用镶嵌的<li>来生成菜单内容,并且包含在<nav>标签中,如下:
- <nav>
- <h1>导航菜单</h1>
- <ul>
- <li>
- <h2>专题教程</h2>
- <ul>
- <li>
- <h3>HTML专题教程</h3>
- <ul>
- <li><a href="http://www.gbin1.com/tutorials/html5-tutorial/html5-introduction">GBin1专题之HTML5教程 - 第一篇:HTML5介绍</a></li>
- <li><a href="http://www.gbin1.com/tutorials/html5-tutorial/html5-new-elements">GBin1专题之HTML5教程 - 第二篇:HTML5元素</a></li>
- <li><a href="http://www.gbin1.com/tutorials/html5-tutorial/html5-video">GBin1专题之HTML5教程 - 第三篇:HTML5 Video元素</a></li>
- <li><a href="http://www.gbin1.com/tutorials/html5-tutorial/html5-video-doc">GBin1专题之HTML5教程 - 第四篇:HTML5 Video Doc</a></li>
- <li><a href="http://www.gbin1.com/tutorials/html5-tutorial/html5-audio">GBin1专题之HTML5教程 - 第五篇:HTML5 Audio元素</a></li>
- </ul>
- <li>
- <h3>GBin1热点秀</h3>
- <ul>
- <li><a href="http://www.gbin1.com/tutorials/hotspot/hotspot1/">GBin1专题之Web热点秀#1</a>
- <li><a href="http://www.gbin1.com/tutorials/hotspot/hotspot2/">GBin1专题之Web热点秀#2</a>
- <li><a href="http://www.gbin1.com/tutorials/hotspot/hotspot3/">GBin1专题之Web热点秀#3</a>
- </ul>
- </ul>
- 。。。 。。。
Javascript
使用jQuery来查询遍历li,并且生成菜单项目,如下:
- $(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;
- }
搞定! 请参考在线演示查看效果,希望大家喜欢这个简单的效果!
使用jQuery开发iOS风格的页面导航菜单的更多相关文章
- 一款jquery编写图文下拉二级导航菜单特效
一款jquery编写图文下拉二级导航菜单特效,效果非常简洁大气,很不错的一款jquery导航菜单特效. 这款jquery特效适用于很多的个人和门户网站. 适用浏览器:IE8.360.FireFox.C ...
- jQuery制作右侧边垂直二级导航菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jQuery/CSS3类似阿里巴巴的商品导航菜单实现教程
有两天没发表文章了,今天来说说利用jQuery和CSS3制作一款类似阿里巴巴左侧商品菜单导航,这款菜单看起来非常大气,可以展示非常多的产品类目,如果你在设计电子商务网站,不妨可以拿来参考,一下是效果图 ...
- UWP开发---通过委托跨页面导航
-前言 做过.Net开发的都了解,当二级窗口操作主窗口的控件时通常用委托的方式.那么在UWP开发中,常常会遇到MainPage的二级Frame里面的内容去操作MainPage的导航跳转,具体看下图: ...
- WordPress主题开发:输出指定页面导航
实例: <ul> <li class="widget widget_nav_menu"> <?php if(is_page(array(12,14,1 ...
- 用jQuery制作仿网易云课堂导航菜单效果
最近做项目,用到类似的效果. 效果图如下: 直接上代码: HTML: <!DOCTYPE html> <html lang="en"> <head&g ...
- 20款jquery下拉导航菜单特效代码分享
20款jquery下拉导航菜单特效代码分享 jquery仿京东商城左侧分类导航下拉菜单代码 jQuery企业网站下拉导航菜单代码 jQuery css3黑色的多级导航菜单下拉列表代码 jquery响应 ...
- 用CSS做导航菜单的4个理由
导航结构在网站设计中是起到决定性作用的,导航菜单/栏常常通过颜色.排版.形状和一些图片来帮助网站创造更好的视觉和感受,它是网页设计的关键元素.虽然网站导航菜单的外观是网页设计中关系到整个设计成败与否的 ...
- PhotoSwipe - 移动开发必备的 iOS 风格相册
PhotoSwipe 是一个专门针对移动设备的图像画廊,它的灵感来自 iOS 的图片浏览器和谷歌移动端图像. PhotoSwipe 提供您的访客熟悉和直观的界面,使他们能够与您的移动网站上的图像进行交 ...
随机推荐
- 年终知识分享——UML、设计模式、设计原则
...
- DataGridView绑定复杂实体(属性本身又是实体)
今天我们来讨论下一个实体中某个属性又是实体的类型的集合绑定到DataGridView上的问题. 先来写一个Student类 public class Student { public int Stud ...
- JProfiler使用详细教程学习笔记
JProfiler学习笔记 推荐文章:JProfiler 入门教程 一.安装JProfiler 从http://www.ej-technologies.com/下载5.1.2并申请 ...
- 爱上MVC3~MVC+ZTree大数据异步树加载
回到目录 理论部分: MVC+ZTree:指在.net MVC环境下进行开发,ZTree是一个jquery的树插件 大数据:一般我们系统中,有一些表结构属于树型的,如分类,地域,菜单,网站导航等等,而 ...
- paip.检测信用卡账单数据的正确性算法
paip.检测信用卡账单数据的正确性算法 主要3点: //1.重点检测.大钱记录 //2.检测遗漏记录 //3.排除双唇记录. //4.试着cls share,改变错误的cls. 作者Attilax ...
- php计算时间差
echo "今天:".date("Y-m-d")."<br>"; echo "昨天:".date(" ...
- 重新签名IPA ( iPhone )
提示:暂时不能用了,企业证书滥用 ios 企业证书 ipa 重新签名发布 1. 应用场景 当前有一个 未用企业证书签名的 ipa 文件,默认是不可以直接安装到设备上的:我们需要用企业版证书签名: 当前 ...
- win10蓝屏问题,关于驱动kisSaasUrlRedirectKnl64.sys 的
上周末刚从win7升级到win10:今天出现了两次蓝屏了,都是显示: xxxxxxx 百度知道链接---http://zhidao.baidu.com/question/164141456570387 ...
- Windows server 2008 R2充当路由器实现网络的互联(转)
1.路由器的工作原理 当IP子网中的一台主机发送IP分组给同一IP子网的另一台主机时,它将直接把IP分组送到网络上,对方就能收到.而要送给不同IP子网上的主机时,它要 选择一个能到达目的子网上的路由器 ...
- reader
http://git.oschina.net/jayqqaa12/abase-reader https://github.com/JustWayward/BookReader https://gith ...
