nav-bar.html 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>底部导航栏</title>
  7. <!-- 自定义样式 -->
  8. <link rel="stylesheet" href="../css/custom.css">
  9. <!-- FontAwesome -->
  10. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  11. <style>
  12. .nav-bar {
  13. position: fixed;
  14. bottom: 0;
  15. left: 0;
  16. right: 0;
  17. background-color: white;
  18. border-top: 1px solid #eee;
  19. display: flex;
  20. justify-content: space-around;
  21. padding: 10px 0;
  22. box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
  23. z-index: 100;
  24. }
  25. .nav-item {
  26. display: flex;
  27. flex-direction: column;
  28. align-items: center;
  29. color: #888;
  30. font-size: 10px;
  31. transition: color 0.2s;
  32. }
  33. .nav-item.active {
  34. color: var(--color-primary);
  35. }
  36. .nav-item i {
  37. font-size: 22px;
  38. margin-bottom: 2px;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <div class="nav-bar">
  44. <a href="../pages/game-plaza.html" class="nav-item" id="nav-plaza">
  45. <i class="fas fa-gamepad"></i>
  46. <span>游戏广场</span>
  47. </a>
  48. <a href="../pages/room-join.html" class="nav-item" id="nav-room">
  49. <i class="fas fa-door-open"></i>
  50. <span>我的房间</span>
  51. </a>
  52. <a href="../pages/game-history.html" class="nav-item" id="nav-history">
  53. <i class="fas fa-history"></i>
  54. <span>游戏历史</span>
  55. </a>
  56. <a href="../pages/profile.html" class="nav-item" id="nav-profile">
  57. <i class="fas fa-user"></i>
  58. <span>我的</span>
  59. </a>
  60. </div>
  61. <script>
  62. document.addEventListener("DOMContentLoaded", function() {
  63. // 获取当前页面路径
  64. let currentPath = window.parent.location.pathname;
  65. // 匹配路径并设置对应的导航项为活跃状态
  66. if (currentPath.includes('game-plaza')) {
  67. document.getElementById('nav-plaza').classList.add('active');
  68. } else if (currentPath.includes('room-join') || currentPath.includes('room-waiting') || currentPath.includes('room-create')) {
  69. document.getElementById('nav-room').classList.add('active');
  70. } else if (currentPath.includes('game-history')) {
  71. document.getElementById('nav-history').classList.add('active');
  72. } else if (currentPath.includes('profile')) {
  73. document.getElementById('nav-profile').classList.add('active');
  74. } else if (currentPath.includes('game-turtle')) {
  75. // 游戏页面不高亮导航栏中的任何选项
  76. } else {
  77. // 默认选中游戏广场
  78. document.getElementById('nav-plaza').classList.add('active');
  79. }
  80. });
  81. </script>
  82. </body>
  83. </html>