-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
165 lines (148 loc) · 7.24 KB
/
script.js
File metadata and controls
165 lines (148 loc) · 7.24 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
console.log("System initialized. Welcome, Siesta.");
document.addEventListener("DOMContentLoaded", () => {
// 1. 載入畫面
const loadingOverlay = document.getElementById("loading");
const progressBar = document.getElementById("progress-bar");
let progress = 0;
if (loadingOverlay && progressBar) {
const interval = setInterval(() => {
progress += Math.floor(Math.random() * 20) + 10;
if (progress > 100) progress = 100;
progressBar.style.width = `${progress}%`;
if (progress === 100) {
clearInterval(interval);
setTimeout(() => {
const loadingContent = document.querySelector('.loading-content');
if(loadingContent) {
loadingContent.style.transition = 'transform 0.5s ease, opacity 0.5s ease';
loadingContent.style.transform = 'translateY(-100vh)';
loadingContent.style.opacity = '0';
}
setTimeout(() => {
loadingOverlay.style.transition = 'opacity 0.5s ease';
loadingOverlay.style.opacity = "0";
setTimeout(() => { loadingOverlay.style.display = "none"; }, 500);
}, 500);
}, 500);
}
}, 200);
}
// 2. Typed.js
if (window.Typed) {
new Typed(".typing", {
strings: [
'CYBER_SECURITY_ENTHUSIAST',
'PYTHON_DEVELOPER',
'FRONTEND_DESIGNER',
'DIGITAL_CONTENT_CREATOR',
'MDHS_STUDENT'
],
typeSpeed: 60, backSpeed: 40, backDelay: 1500, loop: true, cursorChar: '_'
});
}
// 3. 導覽列
let lastScrollTop = 0;
const navbar = document.getElementById("navbar");
if (navbar) {
window.addEventListener("scroll", () => {
let scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (scrollTop > lastScrollTop && scrollTop > 100) {
navbar.classList.add("hidden");
} else {
navbar.classList.remove("hidden");
}
lastScrollTop = scrollTop;
});
}
// 4. Hero 視差與浮現
const heroImage = document.querySelector('.hero-content');
if (heroImage) {
heroImage.style.transition = 'transform 1s ease-out, opacity 1s ease-out';
heroImage.style.transform = 'translateY(-20px)';
heroImage.style.opacity = '0';
setTimeout(() => {
heroImage.style.transform = 'translateY(0)';
heroImage.style.opacity = '1';
}, 800);
}
const hero = document.getElementById('home');
if (hero) {
window.addEventListener('scroll', () => {
const scrollPosition = window.pageYOffset;
hero.style.backgroundPositionY = `${scrollPosition * 0.5}px`;
});
}
// 5. 滾動觸發動畫
function setupScrollAnimation(sectionSelector, itemSelector, thresholdVal = 0.3) {
const section = document.querySelector(sectionSelector);
const items = document.querySelectorAll(itemSelector);
if (!section || items.length === 0) return;
items.forEach(item => {
item.style.opacity = '0';
item.style.transform = 'translateY(30px)';
item.style.transition = 'opacity 0.6s ease-out, transform 0.6s ease-out';
});
const observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
items.forEach((item, index) => {
setTimeout(() => {
item.style.opacity = '1';
item.style.transform = 'translateY(0)';
}, index * 200);
});
observer.unobserve(section);
}
}, { threshold: thresholdVal });
observer.observe(section);
}
setupScrollAnimation('#contact', '.contact-item', 0.5);
setupScrollAnimation('#goals', '.goal-card', 0.3);
// 6. 點狀背景
function createHalftoneDots() {
const container = document.getElementById('goals');
if (!container) return;
const dotContainer = document.createElement('div');
dotContainer.className = 'halftone-container';
dotContainer.style.position = 'absolute'; dotContainer.style.top = '0'; dotContainer.style.left = '0';
dotContainer.style.width = '100%'; dotContainer.style.height = '100%';
dotContainer.style.pointerEvents = 'none'; dotContainer.style.overflow = 'hidden'; dotContainer.style.zIndex = '0';
container.style.position = 'relative'; container.appendChild(dotContainer);
for (let i = 0; i < 30; i++) {
const dot = document.createElement('div');
dot.style.position = 'absolute'; dot.style.width = `20px`; dot.style.height = `20px`;
dot.style.background = 'rgba(255, 255, 255, 0.05)'; dot.style.borderRadius = '50%';
dot.style.left = `${Math.random() * 100}%`; dot.style.top = `${Math.random() * 100}%`;
dot.animate([{ transform: 'scale(0)', opacity: 1 }, { transform: 'scale(1)', opacity: 0 }], { duration: 4000, iterations: Infinity, delay: Math.random() * 4000 });
dotContainer.appendChild(dot);
}
}
createHalftoneDots();
// 7. Canvas 背景
function createCanvasParticles() {
const contactSection = document.getElementById('contact');
if (!contactSection) return;
const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d');
canvas.style.position = 'absolute'; canvas.style.top = '0'; canvas.style.left = '0';
canvas.style.width = '100%'; canvas.style.height = '100%'; canvas.style.zIndex = '0'; canvas.style.pointerEvents = 'none';
contactSection.insertBefore(canvas, contactSection.firstChild);
let width, height; const particles = []; const particleCount = window.innerWidth < 768 ? 40 : 80;
function resize() { width = canvas.width = contactSection.offsetWidth; height = canvas.height = contactSection.offsetHeight; }
window.addEventListener('resize', resize); resize();
for (let i = 0; i < particleCount; i++) {
particles.push({ x: Math.random() * width, y: Math.random() * height, radius: Math.random() * 2 + 1, vx: (Math.random() - 0.5) * 1, vy: (Math.random() - 0.5) * 1 });
}
function draw() {
ctx.clearRect(0, 0, width, height); ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
for (let i = 0; i < particleCount; i++) {
const p = particles[i]; ctx.beginPath(); ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2); ctx.fill();
p.x += p.vx; p.y += p.vy;
if (p.x < 0 || p.x > width) p.vx *= -1; if (p.y < 0 || p.y > height) p.vy *= -1;
}
requestAnimationFrame(draw);
}
draw();
}
setTimeout(createCanvasParticles, 500);
});
if ('scrollRestoration' in history) history.scrollRestoration = 'manual';
window.scrollTo(0, 0);