-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (72 loc) · 2.53 KB
/
script.js
File metadata and controls
84 lines (72 loc) · 2.53 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
document.addEventListener('DOMContentLoaded', function() {
// Better notification system
const showNotification = (message, type = 'info') => {
const notification = document.createElement('div');
notification.className = `notification ${type}`;
notification.textContent = message;
document.body.appendChild(notification);
// Animation for notification
setTimeout(() => notification.classList.add('show'), 100);
// Auto dismiss after 3 seconds
setTimeout(() => {
notification.classList.remove('show');
notification.addEventListener('transitionend', () => notification.remove());
}, 3000);
};
// Function to handle special cases
const handleSpecialCases = (href, event) => {
if (href === '#forum') {
event.preventDefault();
showNotification('Forum section is under construction!', 'warning');
return true;
}
return false;
};
// Smooth scrolling for all navigation links
document.querySelectorAll('nav ul li a[href^="#"]').forEach(link => {
link.addEventListener('click', function(event) {
const href = this.getAttribute('href');
// Handle special cases
if (handleSpecialCases(href, event)) {
return;
}
// Smooth scroll to section
if (href.startsWith('#')) {
event.preventDefault();
const targetElement = document.querySelector(href);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 70,
behavior: 'smooth'
});
}
}
});
});
// Add active class to navigation items when scrolling
window.addEventListener('scroll', function() {
const sections = document.querySelectorAll('section');
const navItems = document.querySelectorAll('nav ul li a');
let currentSection = '';
let previousActiveItem = null;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (pageYOffset >= (sectionTop - 150)) {
currentSection = section.getAttribute('id');
}
});
if (currentSection) {
const currentActiveItem = document.querySelector(`nav ul li a[href="#${currentSection}"]`);
if (previousActiveItem !== currentActiveItem) {
if (previousActiveItem) {
previousActiveItem.classList.remove('active');
}
if (currentActiveItem) {
currentActiveItem.classList.add('active');
}
previousActiveItem = currentActiveItem;
}
}
});
});