使用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 提供您的访客熟悉和直观的界面,使他们能够与您的移动网站上的图像进行交 ...
随机推荐
- Hive的安装部署
1.环境准备 1.1软件版本 hive-0.14 下载地址 2.配置 安装hive的前提,必需安装好hadoop环境,可以参考我之前Hadoop社区版搭建,先搭建好hadoop环境:接下来我们开始配置 ...
- QT自定义精美换肤界面
陆陆续续用QT开发过很多项目,也用QT写过不少私活项目,也写过N个工具,一直梦寐以求能像VC一样可以很方便的有个自定义的界面,QSS的强大让我看到了很好的希望,辗转百度谷歌无数次,一直搜索QT相关的换 ...
- 通过Anuglar Material串串学客户端开发 - NodeJS模块机制之Module.Exports
module.exports 前文讲到在Angular Material的第二个编译文件docs/gulpfile.js中却看到了一个奇怪的东西module.exports那么module.expor ...
- jenkins和docker 使用docker作为slave
使用docker作为jenkins slave. 文章来自:http://www.ciandcd.com文中的代码来自可以从github下载: https://github.com/ciandcd 参 ...
- (笔记)VC6插件安装(VC6LineNumberAddin)
VC6插件安装步骤如下: 1.下载VC6LineNumberAddin插件及注册文件.(以下是参考链接:) http://files.cnblogs.com/files/tdyizhen1314/VC ...
- jQuery实现左移右移
<html> <head> <meta charset="utf-8"> <title>完成左移右移</title> & ...
- 记忆化搜索hdu1078 dfs
http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意:给出n*n的格子,每个各自里面有些食物,问一只老鼠每次走最多k步所能吃到的最多的食物 #includ ...
- SqlServer 查看事务锁及执行语句
一.查看当前锁定的事务 ,) ,用户机器名称,) ,是否被锁住),blocked) ,数据库名称,),cmd 命令,waittype as 等待类型 ,last_batch 最后批处理时间,open_ ...
- chrome诡异的Provisional headers are shown
昨天吐槽了cocos2d-js的问题,所以就准备调研几个其它HTML5引擎,发现PIXI性能极高,但是没有音频.而Phaser.js是在PIXI.js的基础之上进行的封装.而国内有一家公司,开发一个叫 ...
- Dreamweaver8 查找和替换窗口不见了解决办法
激活窗口,按下Atrl+空格,再按下M,方向键移动窗口,就回来了!
