JQ+MUI app 底部导航切换

Love The Way You Lie 2021-09-16 11:38 405阅读 0赞

1.创建文件

index.html

xiaoshipin.html

shangcheng.html

wode.html

footer.html

footer.css

2.每个文件均引入

  1. <link rel="stylesheet" href="../../css/common/mui.min.css" />
  2. <link rel="stylesheet" href="../../css/common/iconfont.css" />
  3. <link rel="stylesheet" href="../../css/common/footer.css" />
  4. <script type="text/javascript" src="../../js/common/jquery-3.2.1.min.js" ></script>
  5. <script type="text/javascript" src="../../js/common/mui.js" ></script>
  6. <script type="text/javascript" src="../../js/common/initDfault.js" ></script>

3.footer.css

  1. .footer {
  2. position: fixed;
  3. bottom: 0;
  4. width: 100%;
  5. }
  6. #footer_ul {
  7. display: flex;
  8. padding: 0;
  9. }
  10. .footer-li {
  11. list-style: none;
  12. flex: 25%;
  13. text-align: center;
  14. }
  15. .footer_ft_color{
  16. color: red;
  17. }

4.initDfault.js 这个文件直接复制粘贴调用footer();即可

  1. // 底部导航方法
  2. function footer() {
  3. $.ajaxSettings.async = false;
  4. $("body").append("<div class='footers'></div>");
  5. var data = {
  6. len: 1,
  7. tpl: "footer",
  8. dom: ".footers"
  9. };
  10. getMuBan(data.tpl, data.dom);
  11. }
  12. // 跳转方法
  13. function changeLocation(p) {
  14. createNew = true;
  15. //跳转动画效果
  16. var ani = p.ani ? p.ani : "slide-in-right";
  17. mui.openWindow({
  18. url: p.page,
  19. id: p.id,
  20. createNew: createNew,
  21. extras: {},
  22. show: {
  23. autoShow: true, //页面loaded事件发生后自动显示,默认为true
  24. aniShow: ani, //页面显示动画,默认为”slide-in-right“;
  25. },
  26. waiting: {
  27. autoShow: false
  28. }
  29. });
  30. }
  31. // 获取模板html 参数文件名
  32. function getMuBan(tpl, dom) {
  33. //获取当前页面名称
  34. var cpn = getUrlFileNoExt(location.href);
  35. //当选页面替换icon
  36. var menuObj = {
  37. index: "weizhi",
  38. xiaoshipin: "ai-video",
  39. shangcheng: "shangcheng",
  40. wode: "wode"
  41. };
  42. //要删除的icon
  43. var rmenuObj = {
  44. index: "weizhi",
  45. xiaoshipin: "ai-video",
  46. shangcheng: "shangcheng",
  47. wode: "wode"
  48. };
  49. var str = "../parts/" + tpl + ".html";
  50. $(dom).load(str, function() {
  51. footerLI(cpn, menuObj, rmenuObj);
  52. // 导航点击事件
  53. $(document).on("tap", ".footer-li", function() {
  54. $('.footer-li').removeClass('footer_ft_color');
  55. var listId = $(this).attr("id");
  56. var str = "../pages/" + listId + ".html";
  57. var p = {
  58. id: listId,
  59. page: str
  60. }
  61. changeLocation(p);
  62. })
  63. });
  64. }
  65. // 改变导航样式
  66. function footerLI(ids, menuObj, rmenuObj) {
  67. $.each(menuObj, function(n, v) {
  68. if(ids == n) {
  69. //找到对应的key,替换icon
  70. var icon = "icon-" + rmenuObj[n];
  71. $("#" + ids).addClass("footer_ft_color");
  72. $("#" + ids + " div:nth-child(1) .icon").removeClass(icon).addClass("icon-" + v);
  73. }
  74. if(ids == "") {
  75. //lddClient/html/pages/
  76. $("#index").addClass("footer_ft_color");
  77. $("#index div:nth-child(1) .icon").removeClass('icon-wdwdj1').addClass("icon-wddj1");
  78. }
  79. })
  80. }
  81. // 获取当前页面网址
  82. function getUrlFileNoExt(url) {
  83. url = url || location.href;
  84. var back = getUrlFileName(url);
  85. return back.split(".")[0];
  86. }
  87. function getUrlFileName(url) {
  88. var tmp = new Array(); //临时变量,用于保存分割字符串
  89. tmp = url.split("/"); //按照"/"分割
  90. var cc = tmp[tmp.length - 1]; //获取最后一部分,即文件名和参数
  91. tmp = cc.split("?"); //把参数和文件名分割开
  92. return tmp[0]; //返回值
  93. }

5.调用

index.html

xiaoshipin.html

shangcheng.html

wode.html

  1. <script>
  2. footer();
  3. </script>

6.模板文件 footer.html

  1. <footer class="footer">
  2. <ul id="footer_ul">
  3. <li id="index" class="footer-li" >
  4. <span class="jump">
  5. <div class="" >
  6. <i class="icon iconfont icon-weizhi" style="font-size: 34px !important;"></i>
  7. </div>
  8. <div>身边</div>
  9. </span>
  10. </li>
  11. <li id="xiaoshipin" class="footer-li" >
  12. <span class="jump">
  13. <div class="" >
  14. <i class="icon iconfont icon-ai-video" style="font-size: 34px !important;"></i>
  15. </div>
  16. <div>小视频</div>
  17. </span>
  18. </li>
  19. <li id="shangcheng" class="footer-li" >
  20. <span class="jump">
  21. <div class="" >
  22. <i class="icon iconfont icon-shangcheng" style="font-size: 34px !important;"></i>
  23. </div>
  24. <div>商城</div>
  25. </span>
  26. </li>
  27. <li id="wode" class="footer-li">
  28. <span class="jump">
  29. <div class="" >
  30. <i class="icon iconfont icon-wode" style="font-size: 34px !important;font-weight: 600;"></i>
  31. </div>
  32. <div>我的</div>
  33. </span>
  34. </li>
  35. </ul>
  36. </footer>

发表评论

表情:
评论列表 (有 0 条评论,405人围观)

还没有评论,来说两句吧...

相关阅读

    相关 mui实现底部导航栏页面切换

    1 问题描述 mui是一款最接近原生的框架,对于会使用的人来说十分的便捷易操作,但对于像笔者这样刚入门的小白可是十分的陌生和走了太多的弯路。 对于那些不懂的前端的人,或