站点
This commit is contained in:
1 parent
224ba24fab
commit
5fb210e5a8
7 files changed
+1913
No files matched your search
@@ -0,0 +1,66 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var root = document.documentElement;
|
||||
var themeToggle = document.getElementById('themeToggle');
|
||||
|
||||
if (themeToggle) {
|
||||
themeToggle.addEventListener('click', function () {
|
||||
var next = root.dataset.theme === 'dark' ? 'light' : 'dark';
|
||||
root.dataset.theme = next;
|
||||
try { localStorage.setItem('stg-site-theme', next); } catch (error) {}
|
||||
});
|
||||
}
|
||||
|
||||
var revealEls = Array.prototype.slice.call(document.querySelectorAll('.reveal'));
|
||||
var revealTick = 0;
|
||||
|
||||
function revealInViewport() {
|
||||
var viewportHeight = window.innerHeight || document.documentElement.clientHeight;
|
||||
revealEls.forEach(function (el) {
|
||||
if (el.classList.contains('visible')) return;
|
||||
var rect = el.getBoundingClientRect();
|
||||
if (rect.top < viewportHeight * 0.94 && rect.bottom > 0) el.classList.add('visible');
|
||||
});
|
||||
}
|
||||
|
||||
function scheduleReveal() {
|
||||
if (revealTick) return;
|
||||
revealTick = window.requestAnimationFrame(function () {
|
||||
revealTick = 0;
|
||||
revealInViewport();
|
||||
});
|
||||
}
|
||||
|
||||
revealInViewport();
|
||||
window.addEventListener('scroll', scheduleReveal, { passive: true });
|
||||
window.addEventListener('resize', scheduleReveal);
|
||||
setTimeout(function () {
|
||||
revealEls.forEach(function (el) { el.classList.add('visible'); });
|
||||
}, 2000);
|
||||
|
||||
var lightbox = document.getElementById('lightbox');
|
||||
var lightboxImg = lightbox ? lightbox.querySelector('img') : null;
|
||||
|
||||
function closeLightbox() {
|
||||
if (!lightbox || lightbox.hidden) return;
|
||||
lightbox.hidden = true;
|
||||
lightboxImg.removeAttribute('src');
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
|
||||
if (lightbox) {
|
||||
document.querySelectorAll('img.zoomable').forEach(function (img) {
|
||||
img.addEventListener('click', function () {
|
||||
lightboxImg.src = img.currentSrc || img.src;
|
||||
lightboxImg.alt = img.alt || '';
|
||||
lightbox.hidden = false;
|
||||
document.body.style.overflow = 'hidden';
|
||||
});
|
||||
});
|
||||
lightbox.addEventListener('click', closeLightbox);
|
||||
window.addEventListener('keydown', function (event) {
|
||||
if (event.key === 'Escape') closeLightbox();
|
||||
});
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user