本帖最后由 yaner 于 2025-3-23 00:04 编辑
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>悬停切换导航</title>
- <base target="_blank">
- <style>
- :root {
- --primary-color: #004a9b;
- --active-color: #e60012;
- --button-bg: #1e90ff;
- --button-hover: #1c75d8;
- --sidebar-width: 250px;
- }
- * { margin: 0; padding: 0; box-sizing: border-box; }
- .tab-container {
- max-width: 800px;
- margin: 20px auto;
- background: #fff;
- box-shadow: 0 2px 12px rgba(0,0,0,0.1);
- border-radius: 8px;
- display: flex;
- height: 600px;
- }
- .tab-nav {
- width: var(--sidebar-width);
- background: #f8f8f8;
- border-right: 2px solid #eee;
- border-radius: 8px 0 0 8px;
- padding: 20px 0;
- }
- .tab-trigger {
- padding: 15px 20px;
- font-size: 17px;
- color: #666;
- cursor: pointer;
- transition: all 0.3s;
- }
- .tab-trigger:hover,
- .tab-trigger.active {
- color: var(--active-color);
- background: #e0e0e0;
- }
- .tab-content {
- flex: 1;
- padding: 30px;
- overflow-y: auto;
- }
- .content-pane {
- display: none;
- animation: fadeIn 0.4s ease-out;
- }
- .content-pane.active {
- display: block;
- }
- ul { list-style: none; }
- .nav-button {
- display: block;
- width: 100%;
- max-width: 400px;
- height: 50px;
- margin: 10px 0;
- background: var(--button-bg);
- color: white;
- font-size: 16px;
- text-align: center;
- line-height: 50px;
- border-radius: 8px;
- text-decoration: none;
- transition: background 0.3s ease;
- box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
- }
- .nav-button:hover {
- background: var(--button-hover);
- }
- @keyframes fadeIn {
- from { opacity: 0; transform: translateY(10px); }
- to { opacity: 1; transform: translateY(0); }
- }
- </style>
- </head>
- <body>
- <?php
- // 读取菜单数据文件
- $menu_data = [];
- $current_category = '';
- $file_path = 'website.txt';
- if (file_exists($file_path)) {
- $lines = file($file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- foreach ($lines as $line) {
- $line = trim($line);
- if (strpos($line, ',') === false) {
- $current_category = $line;
- $menu_data[$current_category] = [];
- } else {
- [$title, $link, $desc] = array_pad(explode(',', $line, 3), 3, '');
- $menu_data[$current_category][] = [
- 'title' => trim($title),
- 'link' => trim($link),
- 'desc' => trim($desc)
- ];
- }
- }
- }
- $categories = array_keys($menu_data);
- ?>
- <div class="tab-container">
- <nav class="tab-nav">
- <?php foreach ($categories as $i => $category): ?>
- <div class="tab-trigger <?= $i === 0 ? 'active' : '' ?>" onmouseover="switchTab('cat<?= $i ?>')"><?= htmlspecialchars($category) ?></div>
- <?php endforeach; ?>
- </nav>
- <div class="tab-content">
- <?php foreach ($categories as $i => $category): ?>
- <div id="cat<?= $i ?>" class="content-pane <?= $i === 0 ? 'active' : '' ?>">
- <ul>
- <?php foreach ($menu_data[$category] as $item): ?>
- <li><a href="<?= htmlspecialchars($item['link']) ?>" class="nav-button" title="<?= htmlspecialchars($item['desc']) ?>"><?= htmlspecialchars($item['title']) ?></a></li>
- <?php endforeach; ?>
- </ul>
- </div>
- <?php endforeach; ?>
- </div>
- </div>
- <script>
- function switchTab(tabId) {
- document.querySelectorAll('.tab-trigger').forEach(t => t.classList.remove('active'));
- document.querySelectorAll('.content-pane').forEach(p => p.classList.remove('active'));
- event.target.classList.add('active');
- document.getElementById(tabId).classList.add('active');
- }
- </script>
- </body>
- </html>
复制代码
web.php
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>悬停切换导航</title>
- <base target="_blank">
- <style>
- :root {
- --primary-color: #004a9b;
- --active-color: #e60012;
- --button-bg: #1e90ff;
- --button-hover: #1c75d8;
- --sidebar-width: 250px;
- }
- * { margin: 0; padding: 0; box-sizing: border-box; }
- .tab-container {
- max-width: 800px;
- margin: 20px auto;
- background: #fff;
- box-shadow: 0 2px 12px rgba(0,0,0,0.1);
- border-radius: 8px;
- display: flex;
- height: 600px;
- }
- .tab-nav {
- width: var(--sidebar-width);
- background: #f8f8f8;
- border-right: 2px solid #eee;
- border-radius: 8px 0 0 8px;
- padding: 20px 0;
- }
- .tab-trigger {
- padding: 15px 20px;
- font-size: 17px;
- color: #666;
- cursor: pointer;
- transition: all 0.3s;
- }
- .tab-trigger:hover,
- .tab-trigger.active {
- color: var(--active-color);
- background: #e0e0e0;
- }
- .tab-content {
- flex: 1;
- padding: 30px;
- overflow-y: auto;
- }
- .content-pane {
- display: none;
- animation: fadeIn 0.4s ease-out;
- }
- .content-pane.active {
- display: block;
- }
- ul { list-style: none; }
- .nav-button {
- display: block;
- width: 100%;
- max-width: 400px;
- height: 50px;
- margin: 10px 0;
- background: var(--button-bg);
- color: white;
- font-size: 16px;
- text-align: center;
- line-height: 50px;
- border-radius: 8px;
- text-decoration: none;
- transition: background 0.3s ease;
- box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
- }
- .nav-button:hover {
- background: var(--button-hover);
- }
- @keyframes fadeIn {
- from { opacity: 0; transform: translateY(10px); }
- to { opacity: 1; transform: translateY(0); }
- }
- /* 分类标题样式 */
- .category-title {
- font-size: 20px;
- color: var(--primary-color);
- margin-bottom: 15px;
- padding-bottom: 5px;
- border-bottom: 2px solid #eee;
- display: none; /* 默认隐藏 */
- }
- /* 移动端样式 */
- @media screen and (max-width: 768px) {
- .tab-container {
- display: block;
- height: auto;
- padding: 20px;
- }
- .tab-nav {
- display: none; /* 隐藏侧边栏 */
- }
- .tab-content {
- padding: 0;
- }
- .content-pane {
- display: block; /* 全部显示 */
- margin-bottom: 30px;
- }
- .content-pane.active {
- display: block;
- }
- .category-title {
- text-align: center;
- display: block; /* 移动端显示标题 */
- }
- .nav-button {
- max-width: 100%;
- }
- }
- /* 桌面端确保标题隐藏 */
- @media screen and (min-width: 769px) {
- .category-title {
- display: none !important; /* 强制隐藏标题 */
- }
- }
- </style>
- </head>
- <body>
- <?php
- // 读取菜单数据文件
- $menu_data = [];
- $current_category = '';
- $file_path = 'website.txt';
- if (file_exists($file_path)) {
- $lines = file($file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- foreach ($lines as $line) {
- $line = trim($line);
- if (strpos($line, ',') === false) {
- $current_category = $line;
- $menu_data[$current_category] = [];
- } else {
- [$title, $link, $desc] = array_pad(explode(',', $line, 3), 3, '');
- $menu_data[$current_category][] = [
- 'title' => trim($title),
- 'link' => trim($link),
- 'desc' => trim($desc)
- ];
- }
- }
- }
- $categories = array_keys($menu_data);
- ?>
- <div class="tab-container">
- <nav class="tab-nav">
- <?php foreach ($categories as $i => $category): ?>
- <div class="tab-trigger <?= $i === 0 ? 'active' : '' ?>" onmouseover="switchTab('cat<?= $i ?>')"><?= htmlspecialchars($category) ?></div>
- <?php endforeach; ?>
- </nav>
- <div class="tab-content">
- <?php foreach ($categories as $i => $category): ?>
- <div id="cat<?= $i ?>" class="content-pane <?= $i === 0 ? 'active' : '' ?>">
- <h2 class="category-title"><?= htmlspecialchars($category) ?></h2>
- <ul>
- <?php foreach ($menu_data[$category] as $item): ?>
- <li><a href="<?= htmlspecialchars($item['link']) ?>" class="nav-button" title="<?= htmlspecialchars($item['desc']) ?>"><?= htmlspecialchars($item['title']) ?></a></li>
- <?php endforeach; ?>
- </ul>
- </div>
- <?php endforeach; ?>
- </div>
- </div>
- <script>
- function switchTab(tabId) {
- document.querySelectorAll('.tab-trigger').forEach(t => t.classList.remove('active'));
- document.querySelectorAll('.content-pane').forEach(p => p.classList.remove('active'));
- event.target.classList.add('active');
- document.getElementById(tabId).classList.add('active');
- }
- // 在移动端不需要切换功能,所以只在桌面端启用
- if (window.innerWidth > 768) {
- document.querySelectorAll('.tab-trigger').forEach(trigger => {
- trigger.addEventListener('mouseover', function(e) {
- switchTab(e.target.getAttribute('onmouseover').match(/'([^']+)'/)[1]);
- });
- });
- }
- </script>
- </body>
- </html>
复制代码 web.php 兼顾移动端显示
- 省教育厅
- 职业教育高质量发展新举措,/edu/policy.html,2025年全省教育工作部署
- 教师帮培计划进展,/edu/training.html,首批300名教师培训完成
- 校园食品安全专项,/edu/food-safety.html,抽检合格率98.7%
- 省经信厅
- 工业增加值数据,/economy/growth.html,同比增长6.8%
- 轻工认证中心,/economy/certification.html,新增国家级认证中心2个
- 盐化工升级规划,/economy/upgrade.html,2025年智能化生产线规划
- 今日盐校
- 新校区建设进度,/school/campus.html,2025年9月投入使用计划
- 毕业生就业数据,/school/employment.html,盐业相关专业就业率100%
- 跨省教学合作,/school/cooperation.html,与江西陶瓷工艺美院共建基地
- 留言
- 留言本,https://gb.gwxy.net,拐翁小院留言本
- 其它
- 维兰网,https://site.xd94.com,维兰网2023版
复制代码 website.txt
|