zoukankan      html  css  js  c++  java
  • MUI底部导航栏切换效果

    首先是html代码:

     <nav class="mui-bar mui-bar-tab">
                        <a href="view/templates/home/home.html" class="mui-tab-item mui-active" id="defaultTab">
                            <span class="mui-icon iconfont icon-shouye"></span>
                            <span class="mui-tab-label">首页</span>
                        </a>
                        <a href="view/templates/ShopClass/ShopClass.html" class="mui-tab-item">
                            <span class="mui-icon iconfont icon-shop"></span>
                            <span class="mui-tab-label">商城</span>
                        </a>
                        <a href="view/templates/ShopCart/ShopCart.html" class="mui-tab-item">
                            <span class="mui-icon iconfont icon-gouwuche"><span class="mui-badge">5</span></span>
                            <span class="mui-tab-label">购物车</span>
                        </a>
                        <a href="view/templates/person/person.html" class="mui-tab-item">
                            <span class="mui-icon iconfont icon-wode"></span>
                            <span class="mui-tab-label">我的</span>
                        </a>
                    </nav>

    js引用别忘了,引用MUI的js文件

    下面是js代码:

     <script type="text/javascript">
            
        //启用双击监听
            mui.init({
                gestureConfig:{
                    doubletap:true
                },
                subpages:[{
                    url:'view/templates/home/home.html',
                    id:'MainViwe',
                    styles:{
                        top: '0',
                        bottom: '51px'
                    }
                }]
            });
        
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005 //flick 减速系数,系数越大,滚动速度越慢,滚动距离越小,默认值0.0006
        });
    
    //底部选项卡切换跳转
    (function jumpPage(){
            //跳转页面
            var subpages = ['view/templates/home/home.html','view/templates/ShopClass/ShopClass.html', 'view/templates/ShopCart/ShopCart.html', 'view/templates/person/person.html'];
            var subpage_style = {
                top: '44px',
                bottom: '51px'
            };
            var aniShow = {};//动画显示
            //首次启动切滑效果
                 //当前激活选项
                var activeTab = subpages[0];         
                 //选项卡点击事件
                mui('.mui-bar-tab').on('tap', 'a', function(e) {
                    var targetTab = this.getAttribute('href');
                    $('#MainViwe').attr('src',targetTab);
                });
                 //自定义事件,模拟点击“首页选项卡”
                document.addEventListener('gohome', function() {
                    var defaultTab = document.getElementById("defaultTab");
                    //模拟首页点击
                    mui.trigger(defaultTab, 'tap');
                    //切换选项卡高亮
                    var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
                    if (defaultTab !== current) {
                        current.classList.remove('mui-active');
                        defaultTab.classList.add('mui-active');
                    }
    
        });
       
    
            })()
    
        </script>
  • 相关阅读:
    TortoiseGit保存用户名密码的方法
    nginx proxy优化
    tomcat优化
    mongodb 慢SQL查询
    iptables基础知识
    mongostat
    mongodb命令
    nginx libpcre.so.1: cannot open shared object file
    error while loading shared libraries: libmcrypt.so.4
    mongodb常见问题
  • 原文地址:https://www.cnblogs.com/codeDevotee/p/7580157.html
Copyright © 2011-2022 走看看