/* campus-glow 皮肤包脚本:顶条日期 + 首页轮播 + 线上展厅画廊翻页 + 返回顶部,无任何外部依赖 */ (function () { /* 顶条日期(本地时间,YYYY年M月D日 星期X) */ var dateEl = document.getElementById('siteDate'); if (dateEl) { var now = new Date(); var week = ['日', '一', '二', '三', '四', '五', '六'][now.getDay()]; dateEl.textContent = now.getFullYear() + '年' + (now.getMonth() + 1) + '月' + now.getDate() + '日 星期' + week; } /* 首页轮播 */ (function () { var root = document.querySelector('.cg-banner'); if (!root) return; var slides = root.querySelectorAll('.cg-banner-slide'); var dots = root.querySelectorAll('.cg-banner-dots button'); var prevBtn = root.querySelector('.cg-banner-arrow.prev'); var nextBtn = root.querySelector('.cg-banner-arrow.next'); if (!slides.length) return; var current = 0; var timer = null; var INTERVAL = 5000; function show(index) { slides[current].classList.remove('active'); if (dots[current]) dots[current].classList.remove('active'); current = (index + slides.length) % slides.length; slides[current].classList.add('active'); if (dots[current]) dots[current].classList.add('active'); } function start() { stop(); if (slides.length > 1) timer = window.setInterval(function () { show(current + 1); }, INTERVAL); } function stop() { if (timer) { window.clearInterval(timer); timer = null; } } dots.forEach(function (dot, index) { dot.addEventListener('click', function () { show(index); start(); }); }); if (prevBtn) prevBtn.addEventListener('click', function () { show(current - 1); start(); }); if (nextBtn) nextBtn.addEventListener('click', function () { show(current + 1); start(); }); root.addEventListener('mouseenter', stop); root.addEventListener('mouseleave', start); root.addEventListener('focusin', stop); root.addEventListener('focusout', start); start(); })(); /* 线上展厅画廊:按页翻动(每页 = 当前列数),到尾页回卷 */ (function () { var stage = document.querySelector('.cg-gallery-stage'); if (!stage) return; var track = stage.querySelector('.cg-gallery-track'); var items = track ? track.children : []; var prevBtn = stage.querySelector('.cg-gallery-arrow.prev'); var nextBtn = stage.querySelector('.cg-gallery-arrow.next'); if (!track || items.length < 1) return; var page = 0; var timer = null; var INTERVAL = 4500; function perView() { var w = window.innerWidth; if (w <= 640) return 1; if (w <= 992) return 2; return parseInt(stage.getAttribute('data-cols') || '4', 10) || 4; } function pages() { return Math.max(1, Math.ceil(items.length / perView())); } function update() { if (page >= pages()) page = 0; if (page < 0) page = pages() - 1; track.style.transform = 'translateX(-' + (page * 100) + '%)'; } function start() { stop(); if (pages() > 1) { timer = window.setInterval(function () { page++; update(); }, INTERVAL); } } function go(delta) { page += delta; update(); start(); } function stop() { if (timer) { window.clearInterval(timer); timer = null; } } if (prevBtn) prevBtn.addEventListener('click', function () { go(-1); }); if (nextBtn) nextBtn.addEventListener('click', function () { go(1); }); stage.addEventListener('mouseenter', stop); stage.addEventListener('mouseleave', start); window.addEventListener('resize', function () { page = 0; update(); }); update(); start(); })(); /* 返回顶部:滚动一屏后出现,点击平滑回顶 */ (function () { var btn = document.querySelector('.cg-backtop'); if (!btn) return; function toggle() { if (window.scrollY > window.innerHeight * 0.6) { btn.classList.add('visible'); } else { btn.classList.remove('visible'); } } window.addEventListener('scroll', toggle, { passive: true }); btn.addEventListener('click', function () { window.scrollTo({ top: 0, behavior: 'smooth' }); }); toggle(); })(); })();