-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallScript.js
More file actions
103 lines (94 loc) · 3.73 KB
/
allScript.js
File metadata and controls
103 lines (94 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"use strict";
// === Theme Initialization (Run immediately to prevent flash) ===
(function () {
const savedTheme = localStorage.getItem('tomocraft-theme') || 'dark';
document.documentElement.setAttribute('data-theme', savedTheme);
})();
document.addEventListener('DOMContentLoaded', function () {
// === Theme Toggle Listener ===
const themeToggle = document.querySelector('.theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', function () {
const current = document.documentElement.getAttribute('data-theme');
const next = current === 'dark' ? 'light' : 'dark';
document.documentElement.setAttribute('data-theme', next);
localStorage.setItem('tomocraft-theme', next);
});
}
// === Language Toggle Listener ===
const langToggle = document.querySelector('.lang-toggle');
if (langToggle) {
langToggle.addEventListener('click', function () {
const currentPath = window.location.pathname;
if (currentPath.startsWith('/ja')) {
localStorage.setItem('tomocraft-lang', 'en');
window.location.href = currentPath.replace(/^\/ja/, '/en');
} else if (currentPath.startsWith('/en')) {
localStorage.setItem('tomocraft-lang', 'ja');
window.location.href = currentPath.replace(/^\/en/, '/ja');
} else {
localStorage.setItem('tomocraft-lang', 'en');
window.location.href = '/en/';
}
});
}
// === Hamburger Menu ===
let menuOpen = false;
const hamburgerButton = document.querySelector('.hamburger');
const nav = document.querySelector('.nav');
const headerContainer = document.querySelector('.header__container');
const pageTop = document.querySelector('.page-top');
hamburgerButton.addEventListener('click', function () {
hamburgerButton.classList.toggle('open');
nav.classList.toggle('open');
headerContainer.classList.toggle('menu-open');
if (menuOpen) {
menuOpen = false;
document.documentElement.style.overflow = 'unset';
} else {
menuOpen = true;
setTimeout(() => {
if (menuOpen) {
document.documentElement.style.overflow = 'hidden';
}
}, 500);
}
});
// === Scroll: Header bg + Page-top button ===
window.addEventListener('scroll', function () {
if (window.pageYOffset >= 50) {
headerContainer.classList.remove('transparent');
} else {
headerContainer.classList.add('transparent');
}
if (window.pageYOffset >= 200) {
pageTop.style.display = "block";
if (pageTop.style.opacity > 0) {
pageTop.style.opacity = 0;
}
pageTop.style.opacity = 1;
} else {
pageTop.style.opacity = 0;
this.setTimeout(() => {
if (window.pageYOffset >= 200) return;
pageTop.style.display = "none";
}, 5000);
}
});
// === Intersection Observer: Fade-in sections ===
const fadeElements = document.querySelectorAll('.fade-in-section');
if (fadeElements.length > 0) {
const fadeObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
fadeObserver.unobserve(entry.target);
}
});
}, {
threshold: 0.15,
rootMargin: '0px 0px -40px 0px'
});
fadeElements.forEach(el => fadeObserver.observe(el));
}
});