修改layui的后台模板的左侧导航栏可以伸缩的方法


Posted in Javascript onSeptember 10, 2019

原生的左侧导航栏代码:

<div class="layui-side layui-bg-black">
  <div class="layui-side-scroll">
   <!-- 左侧导航区域(可配合layui已有的垂直导航) -->
   <ul class="layui-nav layui-nav-tree" lay-filter="test">
    <li class="layui-nav-item layui-nav-itemed">
     <a class="" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >所有商品</a>
     <dl class="layui-nav-child">
      <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >列表一</a></dd>
      <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >列表二</a></dd>
      <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >列表三</a></dd>
      <dd><a href="">超链接</a></dd>
     </dl>
    </li>
    <li class="layui-nav-item">
     <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >解决方案</a>
     <dl class="layui-nav-child">
      <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >列表一</a></dd>
      <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >列表二</a></dd>
      <dd><a href="">超链接</a></dd>
     </dl>
    </li>
    <li class="layui-nav-item"><a href="">云市场</a></li>
    <li class="layui-nav-item"><a href="">发布商品</a></li>
   </ul>
  </div>
 </div>

自己修改的:

<div class="layui-side layui-bg-black">
  <div class="layui-side-scroll">
    <div title="菜单缩放" class="kit-side-fold"><i class="fa fa-navicon" aria-hidden="true"></i></div>
    <!-- 左侧导航区域(可配合layui已有的垂直导航) -->
    <ul class="layui-nav layui-nav-tree" lay-filter="test">
      <li class="layui-nav-item layui-nav-itemed">
        <a class="" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-user-circle-o fa-lg"></i> <span >生源追踪</span></a>
        <dl class="layui-nav-child">
          <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-list fa-lg"></i> <span >生源列表</span></a></dd>
          <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-clipboard fa-lg"></i> <span >学校信息</span></a></dd>
          <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-file-text fa-lg"></i> <span >工做计划</span></a></dd>
        </dl>
      </li>
      <li class="layui-nav-item">
        <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-vcard fa-lg"></i> <span >学员管理</span></a>
        <dl class="layui-nav-child">
          <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-th-list fa-lg"></i> <span >学员列表</span></a></dd>
          <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-user-o fa-lg"></i> <span >考勤管理</span></a></dd>
          <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-send-o fa-lg"></i> <span >沟通计划</span></a></dd>
          <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-frown-o fa-lg"></i> <span >成绩管理</span></a></dd>
        </dl>
      </li>
      <li class="layui-nav-item">
        <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-diamond fa-lg"></i> <span >管理设置</span></a>
        <dl class="layui-nav-child">
          <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-address-book fa-lg"></i> <span >账号管理</span></a></dd>
          <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-check-square fa-lg"></i> <span >授权管理</span></a></dd>
        </dl>
      </li>
      <li class="layui-nav-item">
        <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-gear fa-lg"></i> <span >系统管理</span></a>
        <dl class="layui-nav-child">
          <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-window-restore fa-lg"></i> <span >系统信息</span></a></dd>
          <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="fa fa-database fa-lg"></i> <span >操作日志</span></a></dd>
        </dl>
      </li>
    </ul>
  </div>
</div>

JQ代码:

<script>
  //JavaScript代码区域
  layui.use('element', function(){
    var element = layui.element;

  });
  var isShow = true; //定义一个标志位
  $('.kit-side-fold').click(function(){
    //选择出所有的span,并判断是不是hidden
    $('.layui-nav-item span').each(function(){
      if($(this).is(':hidden')){
        $(this).show();
      }else{
        $(this).hide();
      }
    });
    //判断isshow的状态
    if(isShow){
      $('.layui-side.layui-bg-black').width(60); //设置宽度
      $('.kit-side-fold i').css('margin-right', '70%'); //修改图标的位置
      //将footer和body的宽度修改
      $('.layui-body').css('left', 60+'px');
      $('.layui-footer').css('left', 60+'px');
      //将二级导航栏隐藏
      $('dd span').each(function(){
        $(this).hide();
      });
      //修改标志位
      isShow =false;
    }else{
      $('.layui-side.layui-bg-black').width(200);
      $('.kit-side-fold i').css('margin-right', '10%');
      $('.layui-body').css('left', 200+'px');
      $('.layui-footer').css('left', 200+'px');
      $('dd span').each(function(){
        $(this).show();
      });
      isShow =true;
    }
  });

</script>

以上这篇修改layui的后台模板的左侧导航栏可以伸缩的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
JavaScript中继承的一些示例方法与属性参考
Aug 07 Javascript
javascript 实现 秒杀,团购 倒计时展示的记录 分享
Jul 12 Javascript
jQuery中:lt选择器用法实例
Dec 29 Javascript
跟我学习javascript的Date对象
Nov 19 Javascript
JS实现的表格操作类详解(添加,删除,排序,上移,下移)
Dec 22 Javascript
jQuery基于cookie实现的购物车实例分析
Dec 24 Javascript
谈谈对JavaScript原生拖放的深入理解
Sep 20 Javascript
浅谈vue中数据双向绑定的实现原理
Sep 14 Javascript
vue嵌套路由与404重定向实现方法分析
May 04 Javascript
微信小程序map组件结合高德地图API实现wx.chooseLocation功能示例
Jan 23 Javascript
vue input输入框关键字筛选检索列表数据展示
Oct 26 Javascript
javascript实现滚轮轮播图片
Dec 13 Javascript
layui固定下拉框的显示条数(有滚动条)的方法
Sep 10 #Javascript
使用layui实现的左侧菜单栏以及动态操作tab项方法
Sep 10 #Javascript
浅谈监听单选框radio改变事件(和layui中单选按钮改变事件)
Sep 10 #Javascript
layui给下拉框、按钮状态、时间赋初始值的方法
Sep 10 #Javascript
微信提示 在浏览器打开 效果实现过程解析
Sep 10 #Javascript
Vue+Koa2+mongoose写一个像素绘板的实现方法
Sep 10 #Javascript
js神秘的电报密码 哈弗曼编码实现
Sep 10 #Javascript
You might like
咖啡知识大全
2021/03/03 新手入门
解析PHP实现下载文件的两种方法
2013/07/05 PHP
php中get_cfg_var()和ini_get()的用法及区别
2015/03/04 PHP
Laravel框架路由管理简单示例
2019/05/07 PHP
jquery 框架使用教程 AJAX篇
2009/10/11 Javascript
javascript验证只能输入数字和一个小数点示例
2013/10/21 Javascript
如何获取网站icon有哪些可行的方法
2014/06/05 Javascript
一个字符串反转函数可实现字符串倒序
2014/09/15 Javascript
JavaScript中合并数组的N种方法
2014/09/16 Javascript
浅谈Javascript的静态属性和原型属性
2015/05/07 Javascript
Javascript动态创建表格及删除行列的方法
2015/05/15 Javascript
IONIC自定义subheader的最佳解决方案
2016/09/22 Javascript
js绑定事件和解绑事件
2017/04/27 Javascript
微信小程序自定义导航隐藏和显示功能
2017/06/13 Javascript
React-Native做一个文本输入框组件的实现代码
2017/08/10 Javascript
node-sass安装失败的原因与解决方法
2017/09/04 Javascript
js根据json数据中的某一个属性来给数据分组的方法
2018/10/08 Javascript
layer提示框添加多个按钮选择的实例
2019/09/12 Javascript
js使用文档就绪函数动态改变页面内容示例【innerHTML、innerText】
2019/11/07 Javascript
浅析JS中NEW的实现原理及重写
2020/02/20 Javascript
JS实现iframe中子父页面跨域通讯的方法分析
2020/03/10 Javascript
Django在Win7下的安装及创建项目hello word简明教程
2014/07/14 Python
Python中用字符串调用函数或方法示例代码
2017/08/04 Python
python skimage 连通性区域检测方法
2018/06/21 Python
Python模拟自动存取款机的查询、存取款、修改密码等操作
2018/09/02 Python
pycharm修改界面主题颜色的方法
2019/01/17 Python
Python实现括号匹配方法详解
2020/02/10 Python
PyQt5实现登录页面
2020/05/30 Python
学会迭代器设计模式,帮你大幅提升python性能
2021/01/03 Python
总结30个CSS3选择器
2017/04/13 HTML / CSS
HTML5 语音搜索(淘宝店语音搜素)
2013/01/03 HTML / CSS
如何用H5实现一个触屏版的轮播器的实例
2017/01/09 HTML / CSS
Nasty Gal英国:美国女性服饰销售网站
2021/03/02 全球购物
高一化学教学反思
2014/02/05 职场文书
学前班教学反思
2016/02/24 职场文书
css3 选择器
2022/05/11 HTML / CSS