mui侧滑导航(左侧)

版权声明:本文采用CC BY-NC-ND 4.0共享协议,允许复制转载,但必须在文首显眼位置保留原文作者、原文链接、版本信息、版权声明等信息。不允许演绎和用于商业用途。 https://blog.csdn.net/kanglovejava/article/details/53538389

MUI-最接近原生APP体验的高性能前端框架
mui侧滑导航(左侧)效果图:
这里写图片描述

导入mui控件需要的css,js文件:

 <link href="../resources/ui/mui-master/dist/css/mui.css" rel="stylesheet"/>
   <script type="text/javascript" src="../resources/js/jquery.js"></script>
   <script type="text/javascript" src="../resources/ui/mui-master/js/mui.min.js"></script>
   <script type="text/javascript" src="../resources/ui/layer/laytpl.js"></script>

实现mui侧滑导航的效果很简单,只需要添加一些class样式就可以实现。

  <div id="offCanvasWrapper" class="mui-off-canvas-wrap mui-draggable">
    <div class="mui-inner-wrap">
    <!--header-->
      <header class="mui-bar mui-bar-nav">
        <a href="#offCanvasSide" class="mui-icon-bars mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title" id="title">事项审批(人事)</h1>
      </header>
      <!--侧滑菜单部分-->
        <aside id="offCanvasSide" class="mui-off-canvas-left">
            <div id="offCanvasSideScroll" class="mui-scroll-wrapper">
                <div class="mui-scroll">
                    <span class="android-only"></span>
                    <div class="content">
                        <p style="margin: 10px 10px;">
                            <button id="offCanvasHide" type="button" class="mui-btn mui-btn-danger mui-btn-block" style="padding: 5px 20px;">流程分类</button>
                        </p>
                    </div>
                    <div id="menu1" class="menu">
                        <ul id="cateen1" class="mui-table-view mui-table-view-chevron mui-table-view-inverted">
                            <script id="canteensrc1" type="text/html">
                                {{# for(var i = 0, len = d.list.length; i < len; i++){ }}
                                    <li class="mui-table-view-cell">
                                    <a   class="mui-navigate-right"href="javascript:void(0);" onClick="addapply('{{d.list[i].id}}')">
                                        {{d.list[i].text}}
                                    </a>
                                    </li>
                                {{# } }}
                            </script>
                        </ul>
                    </div>
                </div>
            </div>
        </aside>
        <!--主页面-->
      <div id="offCanvasContentScroll" class="mui-content mui-scroll-wrapper">
        <div class="mui-scroll">
            <div id="menu" class="menu">
                <ul id="table" class="mui-table-view mui-grid-view mui-grid-9"></ul>
            </div>
        </div>
     </div>
    </div>
</div>

页面加载的时候,ajax请求数据并在主页面显示:

var typeid=$("#typeid").val();//类型值
        var data = _ajax.jsonajax('../exammanager/getFormlist.do?flag=0&typeid='+typeid,false,null,'json');
        var uihtml="";
        $(data.list).each(function(index,value){
            var html="<li class=\"mui-table-view-cell mui-media mui-col-xs-4\"><a href=\"\" onclick=\"apply('"+value.id+"','"+value.attributes+"')\"><span class=\"mui-icon "+value.miconCls+"\"></span><div class=\"mui-media-body\">"+value.name+"</div></a></li>";
            uihtml+=html;
        });
        $("#table").html(uihtml);

侧滑导航栏如下:
这里写图片描述
侧滑菜单数据的加载不太一样:

//侧滑菜单
        var typedata = _ajax.jsonajax('../mobleexammanager/getJbpmTypeTree.do',false,null,'json');
        gettpl = document.getElementById('canteensrc1').innerHTML;
        laytpl(gettpl).render(typedata,function(html){
            $("#cateen1").html(html);
        });

laytpl是一款非常轻量的JavaScript模板引擎,它用巧妙的实现方式,将自身的体积浓缩为不到2KB的字符,laytpl试图打造极致的模版渲染!

//假设你得到了这么一段数据
var data = {
  title: '前端圈',
  intro: '一群码js的骚年,幻想改变世界,却被世界改变。',
  list: [{name: '贤心', city: '杭州'},  {name: '谢亮', city: '北京'}, {name: '浅浅', city: '杭州'}, {name: 'Dem', city: '北京'}]
};

模板:

<h3>{{ d.title }}</h3>
<p class="intro">{{ d.intro }}</p>
<ul>
{{# for(var i = 0, len = d.list.length; i < len; i++){ }}
  <li>
    <span>{{ d.list[i].name }}</span>
    <span>所在城市:{{ d.list[i].city }}</span>
  </li>
{{# } }}
</ul>

网上找到的实例:

//第一步:编写模版。你可以使用一个script标签存放模板,如:
<script id="demo" type="text/html">
<h1>{{ d.title }}</h1>
<ul>
{{# for(var i = 0, len = d.list.length; i < len; i++){ }}
  <li>
    <span>姓名:{{ d.list[i].name }}</span>
    <span>城市:{{ d.list[i].city }}</span>
  </li>
{{# } }}
</ul>
</script>

//第二步:建立视图。用于呈现渲染结果。
<div id="view"></div>

//第三步:渲染模版
var data = {
  title: '前端攻城师',
  list: [{name: '贤心', city: '杭州'}, {name: '谢亮', city: '北京'}, {name: '浅浅', city: '杭州'}, {name: 'Dem', city: '北京'}]
};
var gettpl = document.getElementById('demo').innerHTML;
laytpl(gettpl).render(data, function(html){
  document.getElementById('view').innerHTML = html;
});

我的实例的模板:

<script id="canteensrc1" type="text/html">
                                {{# for(var i = 0, len = d.list.length; i < len; i++){ }}
                                    <li class="mui-table-view-cell">
                                    <a   class="mui-navigate-right"href="javascript:void(0);" onClick="addapply('{{d.list[i].id}}')">
                                        {{d.list[i].text}}
                                    </a>
                                    </li>
                                {{# } }}
                            </script>

ajax获取数据并填充:

//侧滑菜单
        var typedata = _ajax.jsonajax('../mobleexammanager/getJbpmTypeTree.do',false,null,'json');
        gettpl = document.getElementById('canteensrc1').innerHTML;
        laytpl(gettpl).render(typedata,function(html){
            $("#cateen1").html(html);
        });
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页