-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
119 lines (101 loc) · 3.99 KB
/
script.js
File metadata and controls
119 lines (101 loc) · 3.99 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
// Mobile menu functionality
document.addEventListener('DOMContentLoaded', function() {
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const mobileMenu = document.getElementById('mobile-menu');
const menuIcon = mobileMenuBtn.querySelector('.menu-icon');
const closeIcon = mobileMenuBtn.querySelector('.close-icon');
let isMenuOpen = false;
mobileMenuBtn.addEventListener('click', function() {
isMenuOpen = !isMenuOpen;
if (isMenuOpen) {
mobileMenu.classList.remove('hidden');
mobileMenu.classList.add('mobile-menu-open');
menuIcon.classList.add('hidden');
closeIcon.classList.remove('hidden');
} else {
mobileMenu.classList.add('hidden');
mobileMenu.classList.remove('mobile-menu-open');
menuIcon.classList.remove('hidden');
closeIcon.classList.add('hidden');
}
});
// Close mobile menu when clicking on a link
const mobileMenuLinks = mobileMenu.querySelectorAll('a');
mobileMenuLinks.forEach(link => {
link.addEventListener('click', function() {
isMenuOpen = false;
mobileMenu.classList.add('hidden');
mobileMenu.classList.remove('mobile-menu-open');
menuIcon.classList.remove('hidden');
closeIcon.classList.add('hidden');
});
});
// Intersection Observer for animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
const target = entry.target;
const content = target.querySelector('[id$="-content"]');
if (content) {
content.classList.remove('opacity-0', 'translate-y-10');
content.classList.add('opacity-100', 'translate-y-0');
}
}
});
}, observerOptions);
// Observe all sections with data-animate attribute
const animatedSections = document.querySelectorAll('[data-animate]');
animatedSections.forEach(section => {
observer.observe(section);
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offsetTop = target.offsetTop - 80; // Account for fixed nav
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
// Add scroll effect to navigation
let lastScrollTop = 0;
const nav = document.querySelector('nav');
window.addEventListener('scroll', function() {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (scrollTop > lastScrollTop && scrollTop > 100) {
// Scrolling down
nav.style.transform = 'translateY(-100%)';
} else {
// Scrolling up
nav.style.transform = 'translateY(0)';
}
lastScrollTop = scrollTop;
});
// Add transition to nav
nav.style.transition = 'transform 0.3s ease-in-out';
});
// Add loading animation for images
document.addEventListener('DOMContentLoaded', function() {
const images = document.querySelectorAll('img');
images.forEach(img => {
img.addEventListener('load', function() {
this.style.opacity = '1';
});
// Set initial opacity
img.style.opacity = '0';
img.style.transition = 'opacity 0.3s ease';
// If image is already loaded
if (img.complete) {
img.style.opacity = '1';
}
});
});