使用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 提供您的访客熟悉和直观的界面,使他们能够与您的移动网站上的图像进行交 ...
随机推荐
- [Hyper-V]给Hyper-V创建两块网卡备用
描述 给Hyper-V创建两块网卡备用 步骤: 1 打开Hyper-V,在右侧Action栏,单击Virtual Switch Manager… 2 依次选择New Virtual network s ...
- DFD数据流程图
顶层图DFD 0层图 1层图
- [外挂8] 自动挂机 SetTimer函数
>_< : 这里用SetTimer函数自动运行![注意添加在里面的回掉函数函数] UINT SetTimer( HWND hWnd, // 指向窗口句柄 UINT nIDEvent, // ...
- [WinAPI] API 5 [遍历驱动器并获取驱动器属性]
(1) GetLogicalDrives.获取主机中所有的逻辑驱动器,以BitMap的形式返回.◇返回值GetLogicalDrive函数返回一个DWORD类型的值,第一位表示所对应的驱动器是否存在. ...
- Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. 试图加载格式不正确的程序。
出现上述问题的原因是,所加载的程序集中有32位的,也有64位的,IIS 7 程序池 在Windows下.Net FrameWork是64位的,要想正确使用,需要对程序池进行配置.如下图所示:
- 通过Greasemonkey实现网页图片自动点击
昨天受一个朋友所托,实现了一个在特定网页自动点击某超链接图片实现网页跳转功能的JavaScript脚本. 工具就是Firefox的Greasemonkey扩展插件.代码如下: // ==UserScr ...
- [Python] 中文编码问题:raw_input输入、文件读取、变量比较等str、unicode、utf-8转换问题
最近研究搜索引擎.知识图谱和Python爬虫比较多,中文乱码问题再次浮现于眼前.虽然市面上讲述中文编码问题的文章数不胜数,同时以前我也讲述过PHP处理数据库服务器中文乱码问题,但是此处还是准备简单做下 ...
- 阿里云产品介绍(三):云数据库RDS
写完云服务器ECS,本来想先写负载均衡的. 因为发现很多客户,都是直接将单台云服务器应用对外提供访问,如果云服务器宕机,应用就会停止服务.云服务器标称有99.95%的可用率,一年下来宕机四个多小时也是 ...
- Python LDAP中的时间戳转换为Linux下时间
(Get-ADUser zhangsan -Properties badpasswordtime).badpasswordtime返回值为:131172610187388712131172610187 ...
- 用C/C++实现对STORM的执行信息查看和控制
近期公司有个需求.须要在后端应用server上实时获取STORM集群的执行信息和topology相关的提交和控制,经过几天对STORM UI和CMD源代码的分析,得出能够通过其thrift接口调用实现 ...