移动端添加汉堡菜单和侧边导航栏,优化交互体验
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
前端改动: - 添加移动端汉堡菜单按钮(右上角) - 创建侧边导航栏(从右侧滑入) - 包含主导航菜单项 - 包含文档和控制台链接 - 包含登录/注册功能 - 已登录状态显示用户信息和操作菜单 - 移动端隐藏桌面导航链接(文档、控制台、登录、注册) - 侧边栏支持点击遮罩层、关闭按钮、导航链接关闭 - 实现桌面端和移动端登录状态同步 - 使用 MutationObserver 监听登录状态变化 样式改动: - 汉堡菜单三条杠动画效果(点击变叉号) - 侧边栏深色科技风格,渐变背景 - 侧边栏从右侧滑入动画,带遮罩层 - 导航项 hover 效果和滑动动画 - 用户头像和信息卡片样式 - 响应式适配(767px、575px 断点) 交互优化: - banner-list 快速入口卡片改为一行两个(grid 布局) - 调整幻灯片进度条位置(767px: bottom 40px,575px: bottom 60px) - 避免进度条和按钮重合 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
157
js/tools.js
157
js/tools.js
@@ -1,4 +1,161 @@
|
||||
$(function () {
|
||||
// 移动端侧边导航栏控制
|
||||
const mobileMenuToggle = document.getElementById('mobileMenuToggle');
|
||||
const mobileSidebar = document.getElementById('mobileSidebar');
|
||||
const mobileSidebarOverlay = document.getElementById('mobileSidebarOverlay');
|
||||
const mobileSidebarClose = document.getElementById('mobileSidebarClose');
|
||||
|
||||
// 打开侧边栏
|
||||
if (mobileMenuToggle) {
|
||||
mobileMenuToggle.addEventListener('click', function() {
|
||||
mobileSidebar.classList.add('active');
|
||||
mobileMenuToggle.classList.add('active');
|
||||
document.body.style.overflow = 'hidden'; // 禁止页面滚动
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭侧边栏
|
||||
function closeMobileSidebar() {
|
||||
if (mobileSidebar) {
|
||||
mobileSidebar.classList.remove('active');
|
||||
}
|
||||
if (mobileMenuToggle) {
|
||||
mobileMenuToggle.classList.remove('active');
|
||||
}
|
||||
document.body.style.overflow = ''; // 恢复页面滚动
|
||||
}
|
||||
|
||||
// 点击遮罩层关闭
|
||||
if (mobileSidebarOverlay) {
|
||||
mobileSidebarOverlay.addEventListener('click', closeMobileSidebar);
|
||||
}
|
||||
|
||||
// 点击关闭按钮关闭
|
||||
if (mobileSidebarClose) {
|
||||
mobileSidebarClose.addEventListener('click', closeMobileSidebar);
|
||||
}
|
||||
|
||||
// 点击侧边栏内的链接后关闭(可选)
|
||||
document.querySelectorAll('.mobile-nav-link').forEach(function(link) {
|
||||
link.addEventListener('click', function(e) {
|
||||
// 如果是 a 标签且不是 javascript:; 则关闭侧边栏
|
||||
if (link.tagName === 'A' && link.getAttribute('href') !== 'javascript:;') {
|
||||
closeMobileSidebar();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 同步桌面端和移动端的登录状态
|
||||
function syncLoginStatus() {
|
||||
const desktopNoLogin = document.querySelector('.nav-desktop-link.no-login');
|
||||
const desktopLoginIn = document.querySelector('.nav-desktop-link.login-in');
|
||||
const mobileNoLogin = document.querySelector('.mobile-no-login');
|
||||
const mobileLoginIn = document.querySelector('.mobile-login-in');
|
||||
|
||||
// 检查桌面端登录状态
|
||||
if (desktopNoLogin && desktopNoLogin.style.display !== 'none') {
|
||||
// 未登录
|
||||
if (mobileNoLogin) mobileNoLogin.style.display = 'block';
|
||||
if (mobileLoginIn) mobileLoginIn.style.display = 'none';
|
||||
} else if (desktopLoginIn && desktopLoginIn.style.display !== 'none') {
|
||||
// 已登录
|
||||
if (mobileNoLogin) mobileNoLogin.style.display = 'none';
|
||||
if (mobileLoginIn) mobileLoginIn.style.display = 'block';
|
||||
|
||||
// 同步用户信息
|
||||
const desktopUsername = document.getElementById('username');
|
||||
const desktopHeadImg = document.getElementById('headImg');
|
||||
const mobileUsername = document.getElementById('mobileUsername');
|
||||
const mobileHeadImg = document.getElementById('mobileHeadImg');
|
||||
|
||||
if (desktopUsername && mobileUsername) {
|
||||
mobileUsername.textContent = desktopUsername.textContent;
|
||||
}
|
||||
if (desktopHeadImg && mobileHeadImg) {
|
||||
mobileHeadImg.textContent = desktopHeadImg.textContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 移动端登录按钮事件绑定
|
||||
const mobileLoginBtn = document.getElementById('mobileLoginBtn');
|
||||
const desktopLoginBtn = document.getElementById('loginBtn');
|
||||
if (mobileLoginBtn && desktopLoginBtn) {
|
||||
mobileLoginBtn.addEventListener('click', function() {
|
||||
desktopLoginBtn.click();
|
||||
closeMobileSidebar();
|
||||
});
|
||||
}
|
||||
|
||||
// 移动端注册按钮事件绑定
|
||||
const mobileRegistBtn = document.getElementById('mobileRegistBtn');
|
||||
const desktopRegistBtn = document.getElementById('registBtn');
|
||||
if (mobileRegistBtn && desktopRegistBtn) {
|
||||
mobileRegistBtn.addEventListener('click', function() {
|
||||
desktopRegistBtn.click();
|
||||
closeMobileSidebar();
|
||||
});
|
||||
}
|
||||
|
||||
// 移动端账户信息按钮事件绑定
|
||||
const mobileAccountBtn = document.getElementById('mobileAccountBtn');
|
||||
const desktopAccountBtn = document.getElementById('accountBtn');
|
||||
if (mobileAccountBtn && desktopAccountBtn) {
|
||||
mobileAccountBtn.addEventListener('click', function() {
|
||||
desktopAccountBtn.click();
|
||||
closeMobileSidebar();
|
||||
});
|
||||
}
|
||||
|
||||
// 移动端未付款订单按钮事件绑定
|
||||
const mobileFinanceBtn = document.getElementById('mobileFinanceBtn');
|
||||
const desktopFinanceBtn = document.getElementById('financeBtn');
|
||||
if (mobileFinanceBtn && desktopFinanceBtn) {
|
||||
mobileFinanceBtn.addEventListener('click', function() {
|
||||
desktopFinanceBtn.click();
|
||||
closeMobileSidebar();
|
||||
});
|
||||
}
|
||||
|
||||
// 移动端我的工单按钮事件绑定
|
||||
const mobileTicketBtn = document.getElementById('mobileTicketBtn');
|
||||
const desktopTicketBtn = document.getElementById('ticketBtn');
|
||||
if (mobileTicketBtn && desktopTicketBtn) {
|
||||
mobileTicketBtn.addEventListener('click', function() {
|
||||
desktopTicketBtn.click();
|
||||
closeMobileSidebar();
|
||||
});
|
||||
}
|
||||
|
||||
// 移动端退出按钮事件绑定
|
||||
const mobileLogout = document.getElementById('mobileLogout');
|
||||
const desktopLogout = document.getElementById('logout');
|
||||
if (mobileLogout && desktopLogout) {
|
||||
mobileLogout.addEventListener('click', function() {
|
||||
desktopLogout.click();
|
||||
closeMobileSidebar();
|
||||
});
|
||||
}
|
||||
|
||||
// 初始化时同步登录状态
|
||||
setTimeout(syncLoginStatus, 100);
|
||||
|
||||
// 监听登录状态变化(使用 MutationObserver)
|
||||
const observeLoginStatus = function() {
|
||||
const desktopNoLogin = document.querySelector('.nav-desktop-link.no-login');
|
||||
const desktopLoginIn = document.querySelector('.nav-desktop-link.login-in');
|
||||
|
||||
if (desktopNoLogin) {
|
||||
const observer = new MutationObserver(syncLoginStatus);
|
||||
observer.observe(desktopNoLogin, { attributes: true, attributeFilter: ['style'] });
|
||||
}
|
||||
if (desktopLoginIn) {
|
||||
const observer = new MutationObserver(syncLoginStatus);
|
||||
observer.observe(desktopLoginIn, { attributes: true, attributeFilter: ['style'] });
|
||||
}
|
||||
};
|
||||
observeLoginStatus();
|
||||
|
||||
// 产品详情页的图片预览轮播(仅在存在时初始化)
|
||||
if ($('.gallery-thumbs').length > 0 && $('.gallery-top').length > 0) {
|
||||
var galleryThumbs = new Swiper('.gallery-thumbs', {
|
||||
|
||||
Reference in New Issue
Block a user