|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 6 | + <title>导航条带有跳跃动画</title> |
| 7 | + <style> |
| 8 | + body { |
| 9 | + margin: 0; |
| 10 | + padding: 0; |
| 11 | + background-color: #1c1c1c; |
| 12 | + font-family: Arial, "Ping Fang SC", "Microsoft Yahei", sans-serif; |
| 13 | + display: flex; |
| 14 | + justify-content: center; |
| 15 | + align-items: center; |
| 16 | + height: 100vh; |
| 17 | + } |
| 18 | + |
| 19 | + .navbar { |
| 20 | + display: flex; |
| 21 | + justify-content: space-around; |
| 22 | + align-items: center; |
| 23 | + background: linear-gradient(135deg, #2f2f2f, #454545); |
| 24 | + width: 90%; |
| 25 | + padding: 15px; |
| 26 | + box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1); |
| 27 | + position: relative; |
| 28 | + } |
| 29 | + |
| 30 | + .navbar a { |
| 31 | + text-decoration: none; |
| 32 | + color: white; |
| 33 | + display: flex; |
| 34 | + flex-direction: column; |
| 35 | + align-items: center; |
| 36 | + font-size: 14px; |
| 37 | + transition: color 0.3s; |
| 38 | + position: relative; |
| 39 | + z-index: 1; |
| 40 | + flex: 1; |
| 41 | + } |
| 42 | + |
| 43 | + .navbar a .icon { |
| 44 | + width: 36px; |
| 45 | + height: 36px; |
| 46 | + margin-bottom: 5px; |
| 47 | + fill: white; |
| 48 | + transition: fill 0.3s; |
| 49 | + } |
| 50 | + |
| 51 | + .navbar a.active { |
| 52 | + color: #28a745; |
| 53 | + } |
| 54 | + |
| 55 | + .navbar a.active .icon { |
| 56 | + fill: #28a745; |
| 57 | + animation: bounce 0.6s; |
| 58 | + } |
| 59 | + |
| 60 | + @keyframes bounce { |
| 61 | + 0%, |
| 62 | + 20%, |
| 63 | + 50%, |
| 64 | + 80%, |
| 65 | + 100% { |
| 66 | + transform: translateY(0); |
| 67 | + } |
| 68 | + 40% { |
| 69 | + transform: translateY(-10px); |
| 70 | + } |
| 71 | + 60% { |
| 72 | + transform: translateY(-5px); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + .highlight { |
| 77 | + position: absolute; |
| 78 | + bottom: 0; |
| 79 | + height: 4px; |
| 80 | + background-color: #28a745; |
| 81 | + width: calc(100% / 5); |
| 82 | + transition: transform 0.5s ease, width 0.5s ease; |
| 83 | + left: 0; |
| 84 | + } |
| 85 | + </style> |
| 86 | + </head> |
| 87 | + <body> |
| 88 | + <div class="navbar"> |
| 89 | + <div class="highlight"></div> |
| 90 | + <a href="#" class="active" onclick="setActive(this)"> |
| 91 | + <svg |
| 92 | + class="icon" |
| 93 | + xmlns="http://www.w3.org/2000/svg" |
| 94 | + viewBox="0 0 24 24" |
| 95 | + > |
| 96 | + <path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z" /> |
| 97 | + </svg> |
| 98 | + 主页 |
| 99 | + </a> |
| 100 | + <a href="#" onclick="setActive(this)"> |
| 101 | + <svg |
| 102 | + class="icon" |
| 103 | + xmlns="http://www.w3.org/2000/svg" |
| 104 | + viewBox="0 0 24 24" |
| 105 | + > |
| 106 | + <path |
| 107 | + d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7 14H8v-2h4v2zm0-4H8v-2h4v2zm0-4H8V7h4v2zm6 8h-4v-2h4v2zm0-4h-4v-2h4v2zm0-4h-4V7h4v2z" |
| 108 | + /> |
| 109 | + </svg> |
| 110 | + 文档 |
| 111 | + </a> |
| 112 | + <a href="#" onclick="setActive(this)"> |
| 113 | + <svg |
| 114 | + class="icon" |
| 115 | + xmlns="http://www.w3.org/2000/svg" |
| 116 | + viewBox="0 0 24 24" |
| 117 | + > |
| 118 | + <path d="M20 2H4v20h16V2zm-2 18H6V4h12v16z" /> |
| 119 | + </svg> |
| 120 | + 扫描 |
| 121 | + </a> |
| 122 | + <a href="#" onclick="setActive(this)"> |
| 123 | + <svg |
| 124 | + class="icon" |
| 125 | + xmlns="http://www.w3.org/2000/svg" |
| 126 | + viewBox="0 0 36 36" |
| 127 | + > |
| 128 | + <path |
| 129 | + d="M18 3c-8.284 0-15 6.716-15 15s6.716 15 15 15 15-6.716 15-15S26.284 3 18 3zm0 4c6.075 0 11 4.925 11 11s-4.925 11-11 11S7 24.075 7 18 11.925 7 18 7zm-4 9v2h8v-2h-8zm0 4v2h8v-2h-8z" |
| 130 | + /> |
| 131 | + </svg> |
| 132 | + 发现 |
| 133 | + </a> |
| 134 | + <a href="#" onclick="setActive(this)"> |
| 135 | + <svg |
| 136 | + class="icon" |
| 137 | + xmlns="http://www.w3.org/2000/svg" |
| 138 | + viewBox="0 0 24 24" |
| 139 | + > |
| 140 | + <path |
| 141 | + d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z" |
| 142 | + /> |
| 143 | + </svg> |
| 144 | + 我的 |
| 145 | + </a> |
| 146 | + </div> |
| 147 | + |
| 148 | + <script> |
| 149 | + function setActive(element) { |
| 150 | + const navbar = document.querySelector(".navbar"); |
| 151 | + const links = navbar.querySelectorAll("a"); |
| 152 | + links.forEach((link) => link.classList.remove("active")); |
| 153 | + element.classList.add("active"); |
| 154 | + const index = Array.from(links).indexOf(element); |
| 155 | + const highlight = document.querySelector(".highlight"); |
| 156 | + highlight.style.transform = `translateX(${index * 100}%)`; |
| 157 | + } |
| 158 | + </script> |
| 159 | + </body> |
| 160 | +</html> |
0 commit comments