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


Posted in Javascript onJuly 07, 2020

效果图

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实现折叠导航菜单的资料请关注三水点靠木其它相关文章!

Javascript 相关文章推荐
IE和Firefox在JavaScript应用中的兼容性探讨
Apr 01 Javascript
JAVASCRIPT实现的WEB页面跳转以及页面间传值方法
May 13 Javascript
JS判断页面加载状态以及添加遮罩和缓冲动画的代码
Oct 11 Javascript
js一般方法改写成面向对象方法的无限级折叠菜单示例代码
Jul 04 Javascript
删除节点的jquery代码
Jan 13 Javascript
javascript实现百度地图鼠标滑动事件显示、隐藏
Apr 02 Javascript
jQuery+Pdo编写login登陆界面
Aug 01 Javascript
js获取元素下的第一级子元素的方法(推荐)
Mar 05 Javascript
Javascript中click与blur事件的顺序详析
Apr 25 Javascript
在vue中多次调用同一个定义全局变量的实例
Sep 25 Javascript
中高级前端必须了解的JS中的内存管理(推荐)
Jul 04 Javascript
原生js无缝轮播插件使用详解
Mar 09 Javascript
React+EggJs实现断点续传的示例代码
Jul 07 #Javascript
JS实现联想、自动补齐国家或地区名称的功能
Jul 07 #Javascript
jQuery 动态粒子效果示例代码
Jul 07 #jQuery
Electron实现应用打包、自动升级过程解析
Jul 07 #Javascript
基于Electron实现桌面应用开发代码实例
Jul 07 #Javascript
基于javascript处理nginx请求过程详解
Jul 07 #Javascript
vue-i18n实现中英文切换的方法
Jul 06 #Javascript
You might like
推荐Discuz!5的PHP代码高亮显示与实现可运行代码
2007/03/15 PHP
Laravel如何使用Redis共享Session
2018/02/23 PHP
JAVASCRIPT实现的WEB页面跳转以及页面间传值方法
2010/05/13 Javascript
asm.js使用示例代码
2013/11/28 Javascript
node.js中的http.response.addTrailers方法使用说明
2014/12/14 Javascript
Angularjs+bootstrap+table多选(全选)支持单击行选中实现编辑、删除功能
2017/03/27 Javascript
详解Angular 自定义结构指令
2017/06/21 Javascript
JavaScript实现的原生态兼容IE6可调可控滚动文字功能详解
2017/09/19 Javascript
详解vuex的简单使用
2018/03/12 Javascript
JavaScript折半查找(二分查找)算法原理与实现方法示例
2018/08/06 Javascript
Vue项目服务器部署之子目录部署方法
2019/05/12 Javascript
基于layui内置模块(element常用元素的操作)
2019/09/20 Javascript
[47:06]DOTA2上海特级锦标赛主赛事日 - 4 败者组第五轮 MVP.Phx VS EG第一局
2016/03/05 DOTA
python控制台显示时钟的示例
2014/02/24 Python
python计算auc指标实例
2017/07/13 Python
单利模式及python实现方式详解
2018/03/20 Python
python并发编程多进程 模拟抢票实现过程
2019/08/20 Python
np.random.seed() 的使用详解
2020/01/14 Python
Python使用Pandas库常见操作详解
2020/01/16 Python
给Python学习者的文件读写指南(含基础与进阶)
2020/01/29 Python
对tensorflow中cifar-10文档的Read操作详解
2020/02/10 Python
Python sublime安装及配置过程详解
2020/06/29 Python
django Model层常用验证器及自定义验证器详解
2020/07/15 Python
使用css3匹配手机屏幕横竖状态
2014/01/27 HTML / CSS
HTML5-WebSocket实现聊天室示例
2016/12/15 HTML / CSS
美国领先的个性化礼品商城:Personalization Mall
2019/07/27 全球购物
工业自动化专业毕业生推荐信
2013/11/18 职场文书
《童年》教学反思
2014/02/18 职场文书
小学生志愿者活动方案
2014/08/23 职场文书
竞聘报告优秀范文
2014/11/06 职场文书
2015年学校政教工作总结
2015/07/20 职场文书
《植物妈妈有办法》教学反思
2016/02/23 职场文书
纯CSS实现hover图片pop-out弹出效果的实例代码
2021/04/16 HTML / CSS
go使用Gin框架利用阿里云实现短信验证码功能
2021/08/04 Golang
openEuler 搭建java开发环境的详细过程
2022/06/10 Servers
python自动获取微信公众号最新文章的实现代码
2022/07/15 Python