/** * 公共组件 - CSS样式和HTML结构 * 直接通过 引用 */ // 公共CSS样式 const commonCSS = ` :root { --neon-cyan: #00f5ff; --neon-pink: #ff00ff; --neon-purple: #9d00ff; --neon-blue: #0066ff; --neon-green: #00ff80; --china-red: #ff4757; --china-gold: #ffd700; --china-orange: #ff6b35; --dark-bg: #0a0a0f; --darker-bg: #050508; --card-bg: rgba(20, 20, 35, 0.8); --text-primary: #ffffff; --text-secondary: #a0a0b0; --text-muted: #6a6a7a; --border-glow: rgba(0, 245, 255, 0.3); --gradient-china: linear-gradient(135deg, #ff4757 0%, #ff6b35 50%, #ffd700 100%); --font-size-xs: 12px; --font-size-sm: 13px; --font-size-base: 14px; --font-size-lg: 15px; --font-size-xl: 16px; --font-size-2xl: 18px; --font-size-3xl: 20px; --line-height: 1.8; } * { margin: 0; padding: 0; box-sizing: border-box; } html { scroll-behavior: smooth; } body { font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--dark-bg); color: var(--text-primary); overflow-x: hidden; max-width: 100vw; line-height: var(--line-height); font-size: var(--font-size-base); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } html, body { position: relative; width: 100%; } .bg-animation { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; background: var(--darker-bg); } .bg-animation::before { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: radial-gradient(ellipse at 20% 20%, rgba(255, 71, 87, 0.05) 0%, transparent 50%), radial-gradient(ellipse at 80% 80%, rgba(255, 215, 0, 0.05) 0%, transparent 50%), radial-gradient(ellipse at 50% 50%, rgba(0, 245, 255, 0.03) 0%, transparent 70%); animation: bgPulse 10s ease-in-out infinite; } @keyframes bgPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } } .navbar { position: sticky; top: 0; left: 0; width: 100%; z-index: 1000; padding: 0.6rem 5%; display: flex; justify-content: space-between; align-items: center; background: rgba(10, 10, 15, 0.95); backdrop-filter: blur(20px); border-bottom: 1px solid var(--border-glow); } .logo { font-size: var(--font-size-xl); font-weight: 700; background: var(--gradient-china); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; text-decoration: none; letter-spacing: 1px; } .nav-links { display: flex; gap: 1.5rem; list-style: none; } .nav-links a { color: var(--text-secondary); text-decoration: none; font-weight: 500; font-size: var(--font-size-sm); transition: color 0.3s ease; } .nav-links a:hover, .nav-links a.active { color: var(--china-red); } .nav-search { display: flex; align-items: center; gap: 0.5rem; background: rgba(255, 255, 255, 0.05); padding: 0.4rem 0.8rem; border-radius: 15px; border: 1px solid var(--border-glow); } .nav-search input { background: transparent; border: none; color: var(--text-primary); outline: none; width: 120px; font-size: var(--font-size-xs); } .nav-search input::placeholder { color: var(--text-muted); } .btn-group { display: flex; gap: 0.8rem; flex-wrap: wrap; margin: 1rem 0; } .btn { padding: 0.5rem 1.2rem; border-radius: 5px; font-weight: 600; cursor: pointer; transition: all 0.3s ease; text-decoration: none; display: inline-block; font-size: var(--font-size-sm); } .btn-primary { background: var(--gradient-china); border: none; color: var(--dark-bg); } .btn-secondary { background: transparent; border: 1px solid var(--china-red); color: var(--china-red); } .btn-success { background: var(--neon-green); border: none; color: var(--dark-bg); } .btn-danger { background: var(--neon-pink); border: none; color: var(--dark-bg); } .btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(255, 71, 87, 0.3); } .alert { padding: 0.8rem 1.2rem; border-radius: 6px; margin: 1rem 0; border-left: 3px solid; position: relative; } .alert-info { background: rgba(0, 245, 255, 0.1); border-color: var(--neon-cyan); } .alert-success { background: rgba(0, 255, 128, 0.1); border-color: var(--neon-green); } .alert-warning { background: rgba(255, 215, 0, 0.1); border-color: var(--china-gold); } .alert-danger { background: rgba(255, 71, 87, 0.1); border-color: var(--china-red); } .alert p { margin: 0; text-indent: 0; font-size: var(--font-size-sm); } .module { background: var(--card-bg); border: 1px solid var(--border-glow); border-radius: 12px; padding: 1.5rem; backdrop-filter: blur(10px); margin-bottom: 1.5rem; } .module-title { font-size: var(--font-size-base); color: var(--china-red); margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid rgba(255, 71, 87, 0.3); position: relative; } .module-title::before { content: ''; position: absolute; bottom: -1px; left: 0; width: 50px; height: 1px; background: var(--gradient-china); } .tag-cloud { display: flex; flex-wrap: wrap; gap: 0.4rem; } .tag { padding: 0.2rem 0.6rem; background: rgba(255, 71, 87, 0.1); border: 1px solid rgba(255, 71, 87, 0.3); border-radius: 12px; color: var(--text-secondary); font-size: var(--font-size-xs); text-decoration: none; transition: all 0.3s ease; } .tag:hover { background: var(--china-red); color: var(--dark-bg); border-color: var(--china-red); } .footer { margin-top: 3rem; padding: 1.5rem 5%; background: rgba(5, 5, 8, 0.9); border-top: 1px solid var(--border-glow); text-align: center; } .footer-text { color: var(--text-muted); font-size: var(--font-size-xs); } .back-to-top { position: fixed; bottom: 30px; right: 30px; width: 40px; height: 40px; background: transparent; border: 2px solid var(--china-red); border-radius: 50%; color: var(--china-red); font-size: 16px; cursor: pointer; opacity: 0; visibility: hidden; transition: all 0.3s ease; z-index: 999; display: flex; align-items: center; justify-content: center; overflow: hidden; } .back-to-top::before { content: ''; position: absolute; top: 50%; left: 50%; width: 0; height: 0; background: var(--china-red); border-radius: 50%; transform: translate(-50%, -50%); transition: all 0.3s ease; z-index: -1; } .back-to-top.show { opacity: 1; visibility: visible; } .back-to-top:hover { color: white; } .back-to-top:hover::before { width: 100%; height: 100%; } .back-to-top-icon { position: relative; z-index: 1; width: 16px; height: 16px; } .reading-progress { position: fixed; top: 0; left: 0; width: 0%; height: 3px; background: var(--gradient-china); z-index: 1001; transition: width 0.1s ease; } .lightbox { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.95); z-index: 10000; justify-content: center; align-items: center; flex-direction: column; } .lightbox.active { display: flex; } .lightbox-image { max-width: 90%; max-height: 85%; object-fit: contain; border-radius: 8px; box-shadow: 0 0 30px rgba(255, 71, 87, 0.5); } .lightbox-caption { color: var(--text-primary); margin-top: 1rem; font-size: var(--font-size-sm); text-align: center; } .lightbox-close { position: absolute; top: 20px; right: 30px; color: var(--text-primary); font-size: 2rem; cursor: pointer; transition: color 0.3s ease; } .lightbox-close:hover { color: var(--china-red); } .lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); color: var(--text-primary); font-size: 2rem; cursor: pointer; padding: 1rem; transition: color 0.3s ease; user-select: none; } .lightbox-nav:hover { color: var(--china-red); } .lightbox-prev { left: 20px; } .lightbox-next { right: 20px; } ::-webkit-scrollbar { width: 6px; height: 6px; } ::-webkit-scrollbar-track { background: var(--darker-bg); } ::-webkit-scrollbar-thumb { background: var(--china-red); border-radius: 3px; } ::-webkit-scrollbar-thumb:hover { background: var(--china-gold); } @media (max-width: 768px) { html, body { overflow-x: hidden !important; max-width: 100vw !important; } .nav-links { display: none; } .back-to-top { bottom: 20px; right: 20px; width: 45px; height: 45px; font-size: 18px; } } @media (max-width: 480px) { .nav-search { display: none; } .navbar { padding: 0.5rem 4%; } .logo { font-size: var(--font-size-base); } .footer { padding: 1rem 4%; } .footer-text { font-size: 10px; } .back-to-top { bottom: 15px; right: 15px; width: 40px; height: 40px; font-size: 16px; } } `; // 公共基础HTML结构(不含导航栏) const commonBaseHTML = `
`; // 导航栏HTML(可选) const navbarHTML = ` `; // 兼容旧版本的完整HTML const commonHTML = commonBaseHTML + navbarHTML; // 公共页脚 const commonFooter = ` `; // 快捷导航CSS const quickNavCSS = ` .quick-nav { position: fixed; right: 15px; bottom: 100px; display: flex; flex-direction: column; gap: 8px; z-index: 999; } .quick-nav-item { width: 44px; height: 44px; background: var(--card-bg); border: 1px solid var(--border-glow); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); text-decoration: none; font-size: 18px; transition: all 0.3s ease; cursor: pointer; backdrop-filter: blur(10px); } .quick-nav-item:hover { background: var(--china-red); color: var(--dark-bg); border-color: var(--china-red); transform: translateX(-3px); box-shadow: 0 4px 15px rgba(255, 71, 87, 0.3); } .quick-nav-item svg { width: 18px; height: 18px; } .quick-nav-tooltip { position: absolute; right: 55px; background: var(--card-bg); border: 1px solid var(--border-glow); padding: 4px 10px; border-radius: 4px; font-size: 12px; color: var(--text-primary); white-space: nowrap; opacity: 0; visibility: hidden; transition: all 0.3s ease; pointer-events: none; } .quick-nav-item:hover .quick-nav-tooltip { opacity: 1; visibility: visible; } @media (max-width: 768px) { .quick-nav { right: 10px; bottom: 80px; } .quick-nav-item { width: 40px; height: 40px; font-size: 16px; } } `; // 快捷导航HTML const quickNavHTML = `
在线客服 💬 我的收藏 浏览历史 📖 意见反馈 📧 返回顶部
`; // 公共JavaScript功能 function initCommonFunctions() { // 返回顶部功能 const backToTop = document.getElementById('backToTop'); if (backToTop) { window.addEventListener('scroll', () => { const winScroll = document.body.scrollTop || document.documentElement.scrollTop; if (winScroll > 300) { backToTop.classList.add('show'); } else { backToTop.classList.remove('show'); } }); } } function scrollToTop() { window.scrollTo({ top: 0, behavior: 'smooth' }); } // 灯箱功能 let currentImageIndex = 0; let galleryImages = []; function openLightbox(index) { currentImageIndex = index; const lightbox = document.getElementById('lightbox'); const lightboxImage = document.getElementById('lightbox-image'); const lightboxCaption = document.getElementById('lightbox-caption'); if (!lightbox || !lightboxImage) return; lightboxImage.src = galleryImages[index].src; if (lightboxCaption) lightboxCaption.textContent = galleryImages[index].caption; lightbox.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeLightbox() { const lightbox = document.getElementById('lightbox'); if (lightbox) { lightbox.classList.remove('active'); document.body.style.overflow = ''; } } function prevImage() { currentImageIndex = (currentImageIndex - 1 + galleryImages.length) % galleryImages.length; updateLightboxImage(); } function nextImage() { currentImageIndex = (currentImageIndex + 1) % galleryImages.length; updateLightboxImage(); } function updateLightboxImage() { const lightboxImage = document.getElementById('lightbox-image'); const lightboxCaption = document.getElementById('lightbox-caption'); if (lightboxImage) lightboxImage.src = galleryImages[currentImageIndex].src; if (lightboxCaption) lightboxCaption.textContent = galleryImages[currentImageIndex].caption; } // 初始化公共组件 function loadCommonComponents() { // 检查是否禁用导航栏(通过data-disable-navbar属性) const disableNavbar = document.body.hasAttribute('data-disable-navbar'); // 插入CSS const style = document.createElement('style'); style.textContent = commonCSS; document.head.appendChild(style); // 插入快捷导航CSS const quickNavStyle = document.createElement('style'); quickNavStyle.textContent = quickNavCSS; document.head.appendChild(quickNavStyle); // 插入公共HTML(根据配置决定是否包含导航栏) const commonContent = document.getElementById('common-content'); if (commonContent) { commonContent.innerHTML = disableNavbar ? commonBaseHTML : commonHTML; } // 插入页脚 const footerContainer = document.getElementById('common-footer'); if (footerContainer) { footerContainer.innerHTML = commonFooter; } // 插入快捷导航 const quickNavContainer = document.getElementById('quick-nav'); if (quickNavContainer) { quickNavContainer.innerHTML = quickNavHTML; } // 初始化公共功能 initCommonFunctions(); // 灯箱键盘事件 document.addEventListener('keydown', (e) => { const lightbox = document.getElementById('lightbox'); if (!lightbox || !lightbox.classList.contains('active')) return; if (e.key === 'Escape') closeLightbox(); if (e.key === 'ArrowLeft') prevImage(); if (e.key === 'ArrowRight') nextImage(); }); // 点击灯箱背景关闭 const lightbox = document.getElementById('lightbox'); if (lightbox) { lightbox.addEventListener('click', (e) => { if (e.target.id === 'lightbox') { closeLightbox(); } }); } } // 页面加载完成后自动执行 document.addEventListener('DOMContentLoaded', loadCommonComponents);
🆕 最新发布 🔥 热门推荐 🎁 免费资源 👑 VIP专区 🎬 视频教程

前端开发

更多 ›

前端框架

更多 ›

工程化工具

更多 ›