$mobileLogo;
}
// 获取LOGO的位置和尺寸
logoTop = logoObj.offset().top;
logoHeight = logoObj.outerHeight();
logoLeft = logoObj.offset().left;
logoWidth = logoObj.outerWidth();
// 计算弹窗的top值(LOGO底部)和left值(LOGO水平居中)
var modalTop = logoTop + logoHeight + 10; // +10是LOGO和弹窗的间距
var modalLeft = logoLeft + (logoWidth - $modalDialog.outerWidth()) / 2;
// 设置弹窗位置
$modalDialog.css({
'top': modalTop + 'px',
'left': modalLeft + 'px',
'transform': 'none !important' // 取消原有居中变形
});
}
// 修复2:汉堡菜单添加click + touchstart双事件,适配移动端触摸
$('#mobileMenuToggle').on('click touchstart', function(e) {
e.preventDefault(); // 阻止默认行为
e.stopPropagation(); // 阻止事件冒泡
$('#mobileSidebar').toggleClass('active');
$('#sidebarOverlay').toggleClass('active');
// 点击菜单后禁止页面滚动
$('body').toggleClass('overflow-hidden');
});
// 修复3:遮罩层点击关闭侧边栏
$('#sidebarOverlay').on('click touchstart', function(e) {
e.preventDefault();
e.stopPropagation();
$('#mobileSidebar').removeClass('active');
$('#sidebarOverlay').removeClass('active');
$('body').removeClass('overflow-hidden');
});
// 修复4:优化左滑关闭侧边栏逻辑,避免和点击冲突
let startX = 0; // 触摸开始X坐标
const sidebar = document.getElementById('mobileSidebar');
// 触摸开始事件
sidebar.addEventListener('touchstart', function(e) {
startX = e.touches[0].clientX; // 获取第一个触摸点的X坐标
}, false);
// 触摸移动事件
sidebar.addEventListener('touchmove', function(e) {
// 仅当侧边栏处于激活(显示)状态时才处理左滑
if (!sidebar.classList.contains('active')) return;
const moveX = e.touches[0].clientX;
const diffX = startX - moveX; // 滑动距离(正为左滑,负为右滑)
// 左滑距离超过50px时,直接关闭侧边栏
if (diffX > 50) {
$('#mobileSidebar').removeClass('active');
$('#sidebarOverlay').removeClass('active');
$('body').removeClass('overflow-hidden');
e.preventDefault(); // 阻止默认滚动行为
}
}, false);
// 修复5:未登录状态拦截商店/排行榜/小黑屋点击,跳转到登录页(使用合法的userId变量)
$('.need-login').on('click touchstart', function(e) {
// 判断是否登录(通过后端注入的userId是否大于0)
const isLogin = !!userId && userId > 0;
if (!isLogin) {
e.preventDefault(); // 阻止原链接跳转
e.stopPropagation();
window.location.href = '/login.html'; // 跳转到登录页面
}
});
// ========== 用户协议弹窗逻辑 - 新增定位调用 ==========
const POPUP_INTERVAL = 10000; // 30秒(测试用,可改回6小时=21600000)
const SEVEN_DAYS = 21600000; // 1天(86400000毫秒)
function showAgreementModal() {
$('#userAgreementModal').modal({
show: true,
backdrop: 'static',
keyboard: false
});
// 弹窗显示后,执行定位到LOGO下方
setTimeout(setModalToLogoBottom, 100);
// 窗口大小变化时,重新定位
$(window).resize(setModalToLogoBottom);
}
function checkPopupCondition() {
const sevenDaysExpire = localStorage.getItem("sevenDaysExpire");
if (sevenDaysExpire && !isNaN(sevenDaysExpire) && Date.now() < parseInt(sevenDaysExpire)) {
return false;
}
const lastPopupTime = localStorage.getItem("lastPopupTime");
const currentTime = Date.now();
if (!lastPopupTime || isNaN(lastPopupTime) || (currentTime - parseInt(lastPopupTime)) >= POPUP_INTERVAL) {
return true;
}
return false;
}
// 清理过期的免弹窗记录
const sevenDaysExpire = localStorage.getItem("sevenDaysExpire");
if (sevenDaysExpire && (isNaN(sevenDaysExpire) || Date.now() >= parseInt(sevenDaysExpire))) {
localStorage.removeItem("sevenDaysExpire");
}
if (checkPopupCondition()) {
showAgreementModal();
localStorage.setItem("lastPopupTime", Date.now().toString());
}
// 我已知晓按钮 - 核心修改:移除刷新页面代码,仅关闭弹窗
$("#btnRefreshContinue").on('click', function(e){
e.preventDefault();
$('#userAgreementModal').modal('hide');
localStorage.setItem("lastPopupTime", Date.now().toString());
localStorage.removeItem("sevenDaysExpire");
});
// 今日不再提醒按钮
$("#btnSevenDays").on('click', function(e){
e.preventDefault();
$('#userAgreementModal').modal('hide');
const oneDayLater = Date.now() + SEVEN_DAYS;
localStorage.setItem("sevenDaysExpire", oneDayLater.toString());
localStorage.setItem("lastPopupTime", Date.now().toString());
});
// 弹窗关闭按钮
$(".user-agreement-modal .close").on('click', function(e){
e.preventDefault();
$('#userAgreementModal').modal('hide');
localStorage.setItem("lastPopupTime", Date.now().toString());
});
});
// 原生JS实现:筛选特定颜色文本并添加渐变色动画
document.addEventListener('DOMContentLoaded', function() {
// 1. 获取所有.xst类的元素,并筛选出颜色不是rgb(51, 51, 51)的元素
const xstElements = document.querySelectorAll('.xst');
const animatedTextElements = []; // 存储需要添加动画的元素
xstElements.forEach(function(element) {
// 获取元素的计算样式(兼容不同浏览器)
const computedStyle = window.getComputedStyle(element);
const color = computedStyle.color;
// 筛选条件:颜色不等于rgb(51, 51, 51)
if (color !== 'rgb(51, 51, 51)') {
element.classList.add('animated-text'); // 添加动画类
animatedTextElements.push(element); // 存入数组备用
console.log(color); // 打印筛选出的元素颜色
}
});
// 2. 定义渐变颜色数组
const colors_hxq = ['#23ff26', '#0700ff', '#ff0080', '#c2c219'];
let count_hxq = 0;
// 3. 定时切换渐变色背景
setInterval(function() {
animatedTextElements.forEach(function(element) {
// 拼接渐变色背景样式(和原jQuery逻辑一致)
const gradient = `linear-gradient(45deg,
${colors_hxq[count_hxq % 4]},
${colors_hxq[(count_hxq + 1) % 4]},
${colors_hxq[(count_hxq + 2) % 4]},
${colors_hxq[(count_hxq + 3) % 4]}
)`;
// 设置背景图片(渐变)
element.style.backgroundImage = gradient;
// 可选:添加背景裁剪,让渐变只作用于文字(原代码可能遗漏,补充更完整)
element.style.webkitBackgroundClip = 'text';
element.style.backgroundClip = 'text';
element.style.color = 'transparent'; // 文字透明显示渐变
});
count_hxq++;
}, 300);
});