-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
133 lines (117 loc) · 4.63 KB
/
Copy pathscript.js
File metadata and controls
133 lines (117 loc) · 4.63 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
// Mobile Navigation Toggle
document.addEventListener('DOMContentLoaded', function() {
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
if (hamburger && navMenu) {
hamburger.addEventListener('click', function() {
const isExpanded = hamburger.getAttribute('aria-expanded') === 'true';
hamburger.setAttribute('aria-expanded', !isExpanded);
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
}
// Close mobile menu when clicking on a link
document.querySelectorAll('.nav-menu a').forEach(link => {
link.addEventListener('click', function() {
hamburger.classList.remove('active');
hamburger.setAttribute('aria-expanded', 'false');
navMenu.classList.remove('active');
});
});
// Smooth scrolling for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const headerOffset = 80;
const elementPosition = target.getBoundingClientRect().top;
// Fixed: Changed window.pageYOffset to window.scrollY
const offsetPosition = elementPosition + window.scrollY - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
});
});
// Header scroll effect
window.addEventListener('scroll', function() {
const header = document.querySelector('.header');
if (!header) return;
if (window.scrollY > 100) {
header.style.background = 'rgba(255, 255, 255, 0.95)';
header.style.backdropFilter = 'blur(10px)';
} else {
header.style.background = '#fff';
header.style.backdropFilter = 'none';
}
});
// Contact form handling
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(contactForm);
const name = formData.get('name');
const email = formData.get('email');
const service = formData.get('service');
const message = formData.get('message');
if (!name || !email || !service || !message) {
alert('Please fill in all fields');
return;
}
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
alert('Please enter a valid email address');
return;
}
alert('Thank you for your message! We will get back to you soon.');
contactForm.reset();
});
}
// Animate elements on scroll using IntersectionObserver
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target); // Stop observing once animated
}
});
}, observerOptions);
// Update it to append your portfolio classes like this:
document.querySelectorAll('.service-card, .recruitment-card, .about-content, .portfolio-card').forEach(el => {
observer.observe(el);
});
// Add loading animation for hero section
const heroContent = document.querySelector('.hero-content');
if (heroContent) {
setTimeout(() => {
heroContent.classList.add('visible');
}, 200);
}
// Preload important images and handle loading states
const images = document.querySelectorAll('img');
let loadedImages = 0;
if (images.length === 0) {
document.body.classList.add('images-loaded');
} else {
images.forEach(img => {
if (img.complete) {
loadedImages++;
if (loadedImages === images.length) document.body.classList.add('images-loaded');
} else {
img.addEventListener('load', () => {
loadedImages++;
if (loadedImages === images.length) {
document.body.classList.add('images-loaded');
}
});
}
});
}
});