JS实现移动端可折叠导航菜单(现代都市风)

效果图

1.html部分

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>index</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="external nofollow" >
  <link rel="stylesheet" href="css/style.css" rel="external nofollow" >
</head>

<body>

<div class="htmleaf-container">
  <div id="wrapper">

  <!-- 菜单 -->
  <div class="menu">
    <img id="menu-bg" src="images/golden-gate-lights.jpg" />
    <ul>
      <li><a href="">About</a></li>
      <li><a href="">Share</a></li>
      <li><a href="">Activity</a></li>
      <li><a href="">Settings</a></li>
      <li><a href="">Contact</a></li>
    </ul>
  </div>

  <div class="screen">
    <div class="navbar"></div>
    <div class="list">
      <div class="item">
        <div class="img"></div>
        <span></span>
        <span></span>
        <span></span>
      </div>
      <div class="item">
        <div class="img"></div>
        <span></span>
        <span></span>
        <span></span>
      </div>
      <div class="item">
        <div class="img"></div>
        <span></span>
        <span></span>
        <span></span>
      </div>
      <div class="item">
        <div class="img"></div>
        <span></span>
        <span></span>
        <span></span>
      </div>
    </div>
    <div class="burger">
      <div class="x"></div>
      <div class="y"></div>
      <div class="z"></div>
    </div>
  </div>

  </div>
</div>

<script src='https://libs.baidu.com/jquery/1.10.2/jquery.min.js'></script>
<script src='js/script.js'></script>
</body>
</html>

2.css部分

/*basic*/
@import "https://fonts.googleapis.com/css?family=Raleway:200,500,700,800";
 @font-face {
 font-family:icomoon;
 src:url(../fonts/icomoon.eot?rretjt);
 src:url(../fonts/icomoon.eot?#iefixrretjt) format('embedded-opentype'),
   url(../fonts/icomoon.woff?rretjt) format('woff'),
   url(../fonts/icomoon.ttf?rretjt) format('truetype'),
   url(../fonts/icomoon.svg?rretjt#icomoon) format('svg');
 font-weight:400;
 font-style:normal
}
[class^=icon-],[class*=" icon-"] {
 font-family:icomoon;
 speak:none;
 font-style:normal;
 font-weight:400;
 font-variant:normal;
 text-transform:none;
 line-height:1;
 -webkit-font-smoothing:antialiased;
 -moz-osx-font-smoothing:grayscale
}
body,html {
 font-size:100%;
 padding:0;
 margin:0
}
*,*:after,*:before {
 -webkit-box-sizing:border-box;
 -moz-box-sizing:border-box;
 box-sizing:border-box
}
.clearfix:before,.clearfix:after {
 content:" ";
 display:table
}
.clearfix:after {
 clear:both
}
body {
 background:#f9f7f6;
 color:#404d5b;
 font-weight:500;
 font-size:1.05em;
 font-family:segoe ui,lucida grande,Helvetica,Arial,microsoft yahei,FreeSans,Arimo,droid sans,wenquanyi micro hei,hiragino sans gb,hiragino sans gb w3,fontawesome,sans-serif
}
a {
 color:#2fa0ec;
 text-decoration:none;
 outline:none
}
a:hover,a:focus {
 color:#74777b
}
.htmleaf-container {
 margin:0 auto;
 text-align:center;
 overflow:hidden
}
.htmleaf-content {
 font-size:150%;
 padding:1em 0
}
.htmleaf-content h2 {
 margin:0 0 2em;
 opacity:.1
}
.htmleaf-content p {
 margin:1em 0;
 padding:5em 0 0;
 font-size:.65em
}
.bgcolor-1 {
 background:#f0efee
}
.bgcolor-2 {
 background:#f9f9f9
}
.bgcolor-3 {
 background:#e8e8e8
}
.bgcolor-4 {
 background:#2f3238;
 color:#fff
}
.bgcolor-5 {
 background:#df6659;
 color:#521e18
}
.bgcolor-6 {
 background:#2fa8ec
}
.bgcolor-7 {
 background:#d0d6d6
}
.bgcolor-8 {
 background:#3d4444;
 color:#fff
}
.bgcolor-9 {
 background:#ef3f52;
 color:#fff
}
.bgcolor-10 {
 background:#64448f;
 color:#fff
}
.bgcolor-11 {
 background:#3755ad;
 color:#fff
}
.bgcolor-12 {
 background:#3498db;
 color:#fff
}
.htmleaf-header {
 padding:1em 190px;
 letter-spacing:-1px;
 text-align:center
}
.htmleaf-header h1 {
 color:#fff;
 font-weight:600;
 font-size:2em;
 line-height:1;
 margin-bottom:0;
 font-family:segoe ui,lucida grande,Helvetica,Arial,microsoft yahei,FreeSans,Arimo,droid sans,wenquanyi micro hei,hiragino sans gb,hiragino sans gb w3,fontawesome,sans-serif
}
.htmleaf-header h1 span {
 font-family:segoe ui,lucida grande,Helvetica,Arial,microsoft yahei,FreeSans,Arimo,droid sans,wenquanyi micro hei,hiragino sans gb,hiragino sans gb w3,fontawesome,sans-serif;
 display:block;
 font-size:60%;
 font-weight:400;
 padding:.8em 0 .5em;
 color:#c3c8cd
}
.htmleaf-demo a {
 color:#1d7db1;
 text-decoration:none
}
.htmleaf-demo {
 width:100%;
 padding-bottom:1.2em
}
.htmleaf-demo a {
 display:inline-block;
 margin:.5em;
 padding:.6em 1em;
 border:3px solid #1d7db1;
 font-weight:700
}
.htmleaf-demo a:hover {
 opacity:.6
}
.htmleaf-demo a.current {
 background:#1d7db1;
 color:#fff
}
.htmleaf-links {
 position:relative;
 display:inline-block;
 white-space:nowrap;
 font-size:1.5em;
 text-align:center
}
.htmleaf-links::after {
 position:absolute;
 top:0;
 left:50%;
 margin-left:-1px;
 width:2px;
 height:100%;
 background:#dbdbdb;
 content:'';
 -webkit-transform:rotate3d(0,0,1,22.5deg);
 transform:rotate3d(0,0,1,22.5deg)
}
.htmleaf-icon {
 display:inline-block;
 margin:.5em;
 padding:0 0;
 width:1.5em;
 text-decoration:none
}
.htmleaf-icon span {
 display:none
}
.htmleaf-icon:before {
 margin:0 5px;
 text-transform:none;
 font-weight:400;
 font-style:normal;
 font-variant:normal;
 font-family:icomoon;
 line-height:1;
 speak:none;
 -webkit-font-smoothing:antialiased
}
.htmleaf-footer {
 width:100%;
 padding-top:10px
}
.htmleaf-small {
 font-size:.8em
}
.center {
 text-align:center
}
.related {
 position:absolute;
 top:100%;
 left:0;
 width:100%;
 color:#fff;
 background:#333;
 text-align:center;
 font-size:1.25em;
 padding:.5em 0;
 overflow:hidden
}
.related>a {
 vertical-align:top;
 width:calc(100% - 20px);
 max-width:340px;
 display:inline-block;
 text-align:center;
 margin:20px 10px;
 padding:25px;
 font-family:segoe ui,lucida grande,Helvetica,Arial,microsoft yahei,FreeSans,Arimo,droid sans,wenquanyi micro hei,hiragino sans gb,hiragino sans gb w3,fontawesome,sans-serif
}
.related a {
 display:inline-block;
 text-align:left;
 margin:20px auto;
 padding:10px 20px;
 opacity:.8;
 -webkit-transition:opacity .3s;
 transition:opacity .3s;
 -webkit-backface-visibility:hidden
}
.related a:hover,.related a:active {
 opacity:1
}
.related a img {
 max-width:100%;
 opacity:.8;
 border-radius:4px
}
.related a:hover img,.related a:active img {
 opacity:1
}
.related h3 {
 font-family:microsoft yahei,sans-serif
}
.related a h3 {
 font-weight:300;
 margin-top:.15em;
 color:#fff
}
.icon-htmleaf-home-outline:before {
 content:"\e5000"
}
.icon-htmleaf-arrow-forward-outline:before {
 content:"\e5001"
}
@media screen and (max-width:50em) {
 .htmleaf-header {
 padding:3em 10% 4em
}
.htmleaf-header h1 {
 font-size:2em
}
}@media screen and (max-width:40em) {
 .htmleaf-header h1 {
 font-size:1.5em
}
}@media screen and (max-width:30em) {
 .htmleaf-header h1 {
 font-size:1.2em
}
}

/*demo1*/
* {
 margin:0;
 padding:0
}
body {
 background:#383c55;
 width:100%;
 height:100%;
 font:12px open sans,sans-serif
}
#wrapper {
 width: 100%;
 height: 100%;
 overflow: hidden;
 position: absolute;
 background: #111;
}
div.screen {
 width: 100%;
 height: 100%;
 overflow:hidden;
 position:absolute;
 top:0;
 left:0;
 background:#31558a;
 -webkit-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -moz-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -ms-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -o-transition:all 500ms cubic-bezier(0,.995,.99,1);
 transition:all 500ms cubic-bezier(0,.995,.99,1)
}
div.screen.animate {
 left:80%;
 -webkit-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -moz-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -ms-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -o-transition:all 500ms cubic-bezier(0,.995,.99,1);
 transition:all 500ms cubic-bezier(0,.995,.99,1)
}
.list {
 margin-top: 100px;
 text-align: left;
}
.item {
 height: 328px;
 padding-left: 182px;
 clear: both;
}
.item .img,.item span {
 background:#214273;
 border-radius:3px
}
.item .img {
 float: left;
 width: 200px;
 height: 200px;
 margin-left: -93px;
}
.item span {
 height: 30px;
 width: 62%;
 margin-bottom: 48px;
 margin-left: 9%;
 float: left;
}
.item span:nth-of-type(3) {
 width:75px;
 margin-botom:0
}
div.burger {
 height: 100px;
 width: 100px;
 position: absolute;
 top: 11px;
 left: 50px;
 cursor: pointer;
}
div.x,div.y,div.z {
 position:absolute;
 margin:auto;
 top:0;
 bottom:0;
 background:#fff;
 border-radius:2px;
 -webkit-transition:all 200ms ease-out;
 -moz-transition:all 200ms ease-out;
 -ms-transition:all 200ms ease-out;
 -o-transition:all 200ms ease-out;
 transition:all 200ms ease-out
}
div.x,div.y,div.z {
 height: 10px;
 width: 60px;
 -webkit-transition:all 100ms ease-out;
 -moz-transition:all 100ms ease-out;
 -ms-transition:all 100ms ease-out;
 -o-transition:all 100ms ease-out;
 transition:all 100ms ease-out
}
div.y.squize {
 width:0;
 -webkit-transition:all 100ms ease-out;
 -moz-transition:all 100ms ease-out;
 -ms-transition:all 100ms ease-out;
 -o-transition:all 100ms ease-out;
 transition:all 100ms ease-out
}
div.y {
 top:39px;
}
div.z {
 top:80px;
}
div.open div.x,div.open div.z {
 top:19px;
 -webkit-transition:all 70ms ease-out;
 -moz-transition:all 70ms ease-out;
 -ms-transition:all 70ms ease-out;
 -o-transition:all 70ms ease-out;
 transition:all 70ms ease-out
}
div.rotate30 {
 -ms-transform:rotate(30deg);
 -webkit-transform:rotate(30deg);
 transform:rotate(30deg);
 -webkit-transition:all 70ms ease-out;
 -moz-transition:all 70ms ease-out;
 -ms-transition:all 70ms ease-out;
 -o-transition:all 70ms ease-out;
 transition:all 70ms ease-out
}
div.rotate150 {
 -ms-transform:rotate(150deg);
 -webkit-transform:rotate(150deg);
 transform:rotate(150deg);
 -webkit-transition:all 70ms ease-out;
 -moz-transition:all 70ms ease-out;
 -ms-transition:all 70ms ease-out;
 -o-transition:all 70ms ease-out;
 transition:all 70ms ease-out
}
div.rotate45 {
 -ms-transform:rotate(45deg);
 -webkit-transform:rotate(45deg);
 transform:rotate(45deg);
 -webkit-transition:all 100ms ease-out;
 -moz-transition:all 100ms ease-out;
 -ms-transition:all 100ms ease-out;
 -o-transition:all 100ms ease-out;
 transition:all 100ms ease-out
}
div.rotate135 {
 -ms-transform:rotate(135deg);
 -webkit-transform:rotate(135deg);
 transform:rotate(135deg);
 -webkit-transition:all 100ms ease-out;
 -moz-transition:all 100ms ease-out;
 -ms-transition:all 100ms ease-out;
 -o-transition:all 100ms ease-out;
 transition:all 100ms ease-out
}
div.navbar {
 height:200px;
 background:#385e97
}
div.menu {
 height:568px;
 width:320px;
 margin-left:-190px;
 opacity:0;
 position:relative;
 -webkit-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -moz-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -ms-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -o-transition:all 500ms cubic-bezier(0,.995,.99,1);
 transition:all 500ms cubic-bezier(0,.995,.99,1)
}
#menu-bg {
 position:absolute;
 left:-10px;
 top:-120px;
 opacity:.3;
 -webkit-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -moz-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -ms-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -o-transition:all 500ms cubic-bezier(0,.995,.99,1);
 transition:all 500ms cubic-bezier(0,.995,.99,1)
}
div.menu.animate #menu-bg {
 width: 350%;
 left: -143px;
 -webkit-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -moz-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -ms-transition:all 500ms cubic-bezier(0,.995,.99,1);
 -o-transition:all 500ms cubic-bezier(0,.995,.99,1);
 transition:all 500ms cubic-bezier(0,.995,.99,1)
}
div.menu.animate {
 width:100%;
 margin-left: -110px;
 opacity: 1;
 -webkit-transition: all 500ms cubic-bezier(0,.995,.99,1);
 -moz-transition: all 500ms cubic-bezier(0,.995,.99,1);
 -ms-transition: all 500ms cubic-bezier(0,.995,.99,1);
 -o-transition: all 500ms cubic-bezier(0,.995,.99,1);
 transition: all 500ms cubic-bezier(0,.995,.99,1);
}
div.menu ul {
 position: relative;
 padding-top: 200px;
}
div.menu ul li {
 list-style: none;
 width: 100%;
 margin-top: 120px;
 text-align: left;
 padding-left: 300px;
 font-size: 50px;
}
div.menu ul li a {
 color:#fff;
 text-decoration:none;
 letter-spacing:1px
}
div.menu.animate ul li {
 margin-left: 80px;
 -webkit-transition:all 800ms cubic-bezier(0,.995,.99,1);
 -moz-transition:all 800ms cubic-bezier(0,.995,.99,1);
 -ms-transition:all 800ms cubic-bezier(0,.995,.99,1);
 -o-transition:all 800ms cubic-bezier(0,.995,.99,1);
 transition:all 800ms cubic-bezier(0,.995,.99,1)
}
div.menu.animate li:nth-of-type(1) {
 transition-delay:0s
}
div.menu.animate li:nth-of-type(2) {
 transition-delay:.06s
}
div.menu.animate li:nth-of-type(3) {
 transition-delay:.12s
}
div.menu.animate li:nth-of-type(4) {
 transition-delay:.18s
}
div.menu.animate li:nth-of-type(5) {
 transition-delay:.24s
}

3.JS部分

$(document).ready(function() {
  if ('ontouchstart' in window) {
    var click = 'touchstart';
  } else {
    var click = 'click';
  }
  $('div.burger').on(click, function () {
    if (!$(this).hasClass('open')) {
      openMenu();
    } else {
      closeMenu();
    }
  });
  $('div.menu ul li a').on(click, function (e) {
    e.preventDefault();
    closeMenu();
  });
  function openMenu() {
    $('div.burger').addClass('open');
    $('div.y').fadeOut(100);
    $('div.screen').addClass('animate');
    setTimeout(function () {
      $('div.x').addClass('rotate30');
      $('div.z').addClass('rotate150');
      $('.menu').addClass('animate');
      setTimeout(function () {
        $('div.x').addClass('rotate45');
        $('div.z').addClass('rotate135');
      }, 100);
    }, 10);
  }
  function closeMenu() {
    $('div.screen, .menu').removeClass('animate');
    $('div.y').fadeIn(150);
    $('div.burger').removeClass('open');
    $('div.x').removeClass('rotate45').addClass('rotate30');
    $('div.z').removeClass('rotate135').addClass('rotate150');
    setTimeout(function () {
      $('div.x').removeClass('rotate30');
      $('div.z').removeClass('rotate150');
    }, 50);
    setTimeout(function () {
      $('div.x, div.z').removeClass('collapse');
    }, 70);
  }
});

以上就是JS实现移动端可折叠导航菜单(现代都市风)的详细内容,更多关于JS实现折叠导航菜单的资料请关注我们其它相关文章!

(0)

相关推荐

  • JS+CSS实现另类带提示效果的竖向导航菜单

    本文实例讲述了JS+CSS实现另类带提示效果的竖向导航菜单.分享给大家供大家参考.具体如下: 这是一款JS+CSS打造另类带提示的竖向导航菜单,觉得挺不错,只是美工水平有限,有兴趣的朋友就请继续完善吧. 运行效果截图如下: 在线演示地址如下: http://demo.jb51.net/js/2015/js-css-alert-txt-nav-menu-demo/ 具体代码如下: <html> <head> <title>带提示的竖向导航菜单</title>

  • JavaScript实战之带收放动画效果的导航菜单

    虽然有很多插件可用,但为了共同提高,我做了一系列JavaScript实战系列的实例,分享给大家,前辈们若有好的建议,请务必指出,免得误人子弟啊! 今天是第一战:带收放动画效果的菜单,效果如下图:(样式有点丑(-^-))  ( 由于在写本文时,用的编辑器不同,暂时添加不了演示效果,这里有:最终完整代码和演示 ) 动画效果:鼠标hover改变所有目标的背景和字体颜色,鼠标移动到'首页导航',显示下面的分组菜单,分组菜单有子菜单,点击可缩放,带动画过度效果!而且,可以随便添加和删除导航菜单和子菜单,不

  • JS无限级导航菜单实现方法

    这里使用layui渲染的导航 实体类 dept.java private int id; //id private String dept_name; //部门名称 private int pid; //上级部门id private int sort_num; //排序值 private int create_id; //创建人 private String create_time; //创建时间 private int modify_id; //修改人 private String modif

  • AngularJS+Bootstrap3多级导航菜单的实现代码

    将介绍如何用AngularJS构建一个强大的web前端系统.angularjs是由Google团队开发的一款非常优秀web前端框架.在当前如此多的web框架下,AngularJS能脱颖而出,从架构设计上就高人一等,双向数据绑定,依赖注入,指令,MVC,模板.Angular.js创新地把后台技术融入前端开发,扫去jQuery一度的光芒.用angularjs就像写后台代码,更规范,更结构化,更可控. 本文将介绍如何实现多限级导航菜单. 目录 1.静态多级菜单实现 2.动态多级菜单实现 1. 静态多级

  • js+div+css下拉导航菜单完整代码分享

    效果预览:http://keleyi.com/keleyi/phtml/menu/1.htm 下拉菜单 js+div+css下拉导航菜单完整代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w

  • JS+CSS实现简单的二级下拉导航菜单效果

    本文实例讲述了JS+CSS实现简单的二级下拉导航菜单效果.分享给大家供大家参考.具体如下: 这是一款CSS配合JavaScript实现二级下拉导航菜单,好像CSS要配合JS才能写出好效果来,本款菜单同样用到了JS,菜单目前支持两级,下拉导航是我们经常用的一种菜单形式,把这个修改一下你就能用了,结构挺简单,相信你会做好的. 运行效果截图如下: 在线演示地址如下: http://demo.jb51.net/js/2015/js-css-simple-2l-fade-down-menu-codes/

  • ABP框架中导航菜单的使用及JavaScript API获取菜单的方法

    每一个WEB应用程序都有导航菜单,Abp也为用户提供了通用的创建和显示菜单方式. 创建菜单 一个应用程序可能包含不同的模块,而每个模块都可能有它自己的菜单项.在Abp中,需要创建一个派生自NavigationProvider的类来定义一个菜单项. 假设我们有一个这样的主菜单: Tasks Reports Administration 1 User Management 2 Role Management 由上可知,Administration菜单项有两个子菜单项.对应的生成方法如下: publi

  • 基于JavaScript实现熔岩灯效果导航菜单

    熔岩灯效果 就是鼠标移入的时候,背景跟着滑过去~ 两方法如下: 方法一:两个文件,一个HTML,一个JS. HTML源码, <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewpo

  • JS中用三种方式实现导航菜单中的二级下拉菜单

    我们在淘宝.搜狐等大型网站上都可以看到使用的一些二级下拉菜单,比如下面这张图片.那么如何实现导航菜单栏中的二级下拉菜单?下面小编给大家分享实现思路. 但是如何实现类似的图片呢?实际上,我们有至少三种方式来实现,下面,我附上代码供大家参考. 1.仅使用html和css <meta charset="UTF-8"> <title>Document</title> <style> *{margin:0;padding: 0;list-style

  • javascript HTML+CSS实现经典橙色导航菜单

    本文实例介绍了javascript结合HTML CSS实现橙色导航菜单,分享给大家供大家参考,具体内容如下 效果图: <html > <head> <title>超漂亮的HTML导航菜单CSS代码</title> <style> #top { display: block; text-align: left; height: 105px; position: relative; z-index: 0; } .m { margin: 0 auto;

  • JS 实现导航菜单中的二级下拉菜单的几种方式

    最近整理了, JS 实现导航菜单中的二级下拉菜单的三种方式,便于项目中应用. 如何实现导航菜单栏中的二级下拉菜单? 我们在淘宝.搜狐等大型网站上都可以看到使用的一些二级下拉菜单,比如下面这张图片. 但是如何实现类似的图片呢?实际上,我们有至少三种方式来实现,下面,我附上代码供大家参考. 1.仅使用html和css <meta charset="UTF-8"> <title>Document</title> <style> *{margin

  • 原生js和jquery分别实现横向导航菜单效果

    本文实例为大家分享了原生js和jquery横向导航菜单的制作方法,供大家参考,具体内容如下 原生javascript实现: 这一次要实现的是鼠标放上去以后,菜单栏被选中的那一栏水平拉伸,鼠标离开后水平收缩.并带有一定的时间性,使肉眼能够看出其拉伸收缩的动画效果. 开始用javascript进行编写: 首先在之前水平方向的导航栏上进行操作,将第一栏和选中栏的样式只改变为背景变黑色,文字变白色 .on,a:hover{background:#000000;color:#FFFFFF;} 之后开始写j

  • 以JavaScript来实现WordPress中的二级导航菜单的方法

    导航菜单 导航菜单早已 "深入民心", 在博客上的应用日益重要且多样. 从本文开始, 我将开展几个关于 WordPress 导航菜单的话题, 讨论如何在 WordPress 上使用和加强导航菜单, 话题间有一定的承接关系, 难度也会逐步增加. WordPress 上的导航菜单一般有两种, 页面导航菜单和分类导航菜单. 可曾记得? WordPress 是可以撰写独立页面的, 页面导航菜单就是以首页和各个独立页面组成的菜单. 而分类导航菜单则是以首页和各个分类组成的菜单. 这是效果演示 既

随机推荐