-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
220 lines (189 loc) · 6.13 KB
/
script.js
File metadata and controls
220 lines (189 loc) · 6.13 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// ================================
// Mobile Menu Toggle
// ================================
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close mobile menu when clicking on a nav link
document.querySelectorAll('.nav-menu a').forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
});
});
// ================================
// Image Carousel
// ================================
let currentSlide = 0;
const slides = document.querySelectorAll('.carousel-slide');
const dotsContainer = document.querySelector('.carousel-dots');
// Create dots
slides.forEach((_, index) => {
const dot = document.createElement('span');
dot.classList.add('dot');
if (index === 0) dot.classList.add('active');
dot.addEventListener('click', () => goToSlide(index));
dotsContainer.appendChild(dot);
});
const dots = document.querySelectorAll('.dot');
function showSlide(n) {
if (slides.length === 0) return;
// Wrap around
if (n >= slides.length) {
currentSlide = 0;
} else if (n < 0) {
currentSlide = slides.length - 1;
} else {
currentSlide = n;
}
// Move carousel
const carouselContainer = document.querySelector('.carousel-container');
carouselContainer.style.transform = `translateX(-${currentSlide * 100}%)`;
// Update dots
dots.forEach((dot, index) => {
dot.classList.toggle('active', index === currentSlide);
});
}
function moveSlide(direction) {
showSlide(currentSlide + direction);
}
function goToSlide(n) {
showSlide(n);
}
// Auto-advance carousel every 5 seconds
let autoSlideInterval = setInterval(() => {
moveSlide(1);
}, 5000);
// Pause auto-advance when user hovers over carousel
const carousel = document.querySelector('.carousel');
if (carousel) {
carousel.addEventListener('mouseenter', () => {
clearInterval(autoSlideInterval);
});
carousel.addEventListener('mouseleave', () => {
autoSlideInterval = setInterval(() => {
moveSlide(1);
}, 5000);
});
}
// ================================
// Keyboard Navigation for Carousel
// ================================
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowLeft') {
moveSlide(-1);
} else if (e.key === 'ArrowRight') {
moveSlide(1);
}
});
// ================================
// Smooth Scroll Enhancement
// ================================
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const navbarHeight = document.querySelector('.navbar').offsetHeight;
const targetPosition = target.offsetTop - navbarHeight - 20;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// ================================
// Scroll Animations
// ================================
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -100px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe all sections for fade-in animation
document.querySelectorAll('.section').forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(20px)';
section.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(section);
});
// ================================
// Active Nav Link on Scroll
// ================================
window.addEventListener('scroll', () => {
let current = '';
const sections = document.querySelectorAll('.section[id]');
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (window.pageYOffset >= sectionTop - 150) {
current = section.getAttribute('id');
}
});
document.querySelectorAll('.nav-menu a').forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
});
// ================================
// Add Loading State for External Links
// ================================
document.querySelectorAll('a[target="_blank"]').forEach(link => {
link.addEventListener('click', function() {
this.style.opacity = '0.6';
setTimeout(() => {
this.style.opacity = '1';
}, 1000);
});
});
// ================================
// Initialize on Page Load
// ================================
document.addEventListener('DOMContentLoaded', () => {
// Show first slide
showSlide(0);
// Add entrance animation to hero
const heroContent = document.querySelector('.hero-content');
if (heroContent) {
setTimeout(() => {
heroContent.style.opacity = '1';
}, 100);
}
console.log('DunamisLAN website loaded successfully!');
});
// ================================
// Touch Swipe Support for Carousel (Mobile)
// ================================
let touchStartX = 0;
let touchEndX = 0;
const carouselElement = document.querySelector('.carousel');
if (carouselElement) {
carouselElement.addEventListener('touchstart', e => {
touchStartX = e.changedTouches[0].screenX;
});
carouselElement.addEventListener('touchend', e => {
touchEndX = e.changedTouches[0].screenX;
handleSwipe();
});
function handleSwipe() {
if (touchEndX < touchStartX - 50) {
moveSlide(1);
}
if (touchEndX > touchStartX + 50) {
moveSlide(-1);
}
}
}