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>
本文来自博客园,作者:沉迷编程的程序员,转载请注明原文链接:https://www.cnblogs.com/codeDevotee/p/7580157.html
欢迎各位找我代写程序,python、c#、web等都可以,加我请注明博客园微信:A15919195482