ner('click', (e) => { e.preventDefault(); // 阻止默认跳转 // 登录状态判断(使用pboot模板标签) // 未登录 - 打开登录提示模态框 openLoginModal(); }); // 其他事件绑定 closePaymentModal.addEventListener('click', closePaymentModalFunc); verifyPaymentBtn.addEventListener('click', openSuccessModal); showRiskBtn.addEventListener('click', openRiskModal); closeRiskModal.addEventListener('click', closeRiskModalFunc); // 登录模态框关闭事件 loginModal.addEventListener('click', (e) => { if (e.target === loginModal) closeLoginModal(); }); // 点击背景关闭模态框 paymentModal.addEventListener('click', (e) => e.target === paymentModal && closePaymentModalFunc()); successModal.addEventListener('click', (e) => { if (e.target === successModal) { successModal.classList.add('opacity-0', 'pointer-events-none'); successModal.querySelector('div').classList.remove('scale-100'); successModal.querySelector('div').classList.add('scale-95'); } }); riskModal.addEventListener('click', (e) => e.target === riskModal && closeRiskModalFunc()); // ESC键关闭所有模态框 document.addEventListener('keydown', (e) => { if (e.key === 'Escape') { !paymentModal.classList.contains('pointer-events-none') && closePaymentModalFunc(); !successModal.classList.contains('pointer-events-none') && ( successModal.classList.add('opacity-0', 'pointer-events-none'), successModal.querySelector('div').classList.remove('scale-100'), successModal.querySelector('div').classList.add('scale-95') ); !riskModal.classList.contains('pointer-events-none') && closeRiskModalFunc(); !loginModal.classList.contains('pointer-events-none') && closeLoginModal(); } }); // 分享功能 // 当前页面信息 const pageInfo = { url: window.location.href, // 当前页面URL title: document.title, // 当前页面标题 summary: '推荐一个好内容给你!', // 分享摘要 pic: 'https://www.bbc7.cn/template/news/zhimalink/image/wx.png' // 分享图片 }; // 分享到QQ function shareToQQ() { const url = `https://connect.qq.com/widget/shareqq/index.html?url=${encodeURIComponent(pageInfo.url)}&title=${encodeURIComponent(pageInfo.title)}&summary=${encodeURIComponent(pageInfo.summary)}&pics=${encodeURIComponent(pageInfo.pic)}`; window.open(url, '_blank', 'width=600,height=500'); } // 分享到QQ空间 function shareToQzone() { const url = `https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=${encodeURIComponent(pageInfo.url)}&title=${encodeURIComponent(pageInfo.title)}&summary=${encodeURIComponent(pageInfo.summary)}&pics=${encodeURIComponent(pageInfo.pic)}`; window.open(url, '_blank', 'width=600,height=500'); } // 分享到新浪微博 function shareToWeibo() { const url = `https://service.weibo.com/share/share.php?url=${encodeURIComponent(pageInfo.url)}&title=${encodeURIComponent(pageInfo.title + ' ' + pageInfo.summary)}&pic=${encodeURIComponent(pageInfo.pic)}`; window.open(url, '_blank', 'width=600,height=500'); } // 分享到抖音(抖音无官方分享接口,这里模拟复制链接提示) function shareToDouyin() { // 复制链接到剪贴板 navigator.clipboard.writeText(pageInfo.url).then(() => { alert('链接已复制,可粘贴到抖音分享'); }).catch(() => { alert('请手动复制链接分享到抖音:' + pageInfo.url); }); } // 导航栏滚动效果 const navbar = document.getElementById('navbar'); window.addEventListener('scroll', () => { if (navbar) { if (window.scrollY > 50) { navbar.classList.add('shadow-md'); navbar.classList.remove('shadow-sm'); } else { navbar.classList.remove('shadow-md'); navbar.classList.add('shadow-sm'); } } // 滚动指示器 const winScroll = document.body.scrollTop || document.documentElement.scrollTop; const height = document.documentElement.scrollHeight - document.documentElement.clientHeight; const scrolled = (winScroll / height) * 100; const scrollIndicator = document.getElementById("scrollIndicator"); if (scrollIndicator) { scrollIndicator.style.width = scrolled + "%"; } }); // 移动端菜单 const mobileMenuBtn = document.getElementById('mobile-menu-btn'); const mobileMenu = document.getElementById('mobile-menu'); if (mobileMenuBtn && mobileMenu) { mobileMenuBtn.addEventListener('click', () => { mobileMenu.classList.toggle('hidden'); }); } // 平滑滚动 document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const targetId = this.getAttribute('href'); if (targetId === '#') return; const targetElement = document.querySelector(targetId); if (targetElement) { window.scrollTo({ top: targetElement.offsetTop - 80, behavior: 'smooth' }); // 关闭移动端菜单 if (mobileMenu && !mobileMenu.classList.contains('hidden')) { mobileMenu.classList.add('hidden'); } } }); }); });