-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
227 lines (194 loc) · 7.21 KB
/
Copy pathscript.js
File metadata and controls
227 lines (194 loc) · 7.21 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
221
222
223
224
225
226
227
// Language Switching
let currentLang = 'en';
function switchLanguage(lang) {
currentLang = lang;
const html = document.documentElement;
// Update HTML attributes
html.setAttribute('lang', lang);
html.setAttribute('dir', lang === 'he' ? 'rtl' : 'ltr');
// Update all elements with data attributes
document.querySelectorAll('[data-en]').forEach(element => {
const text = element.getAttribute(`data-${lang}`);
if (text) {
if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') {
element.placeholder = text;
} else {
element.textContent = text;
}
}
});
// Update select options
document.querySelectorAll('option[data-en]').forEach(option => {
const text = option.getAttribute(`data-${lang}`);
if (text) {
option.textContent = text;
}
});
// Update input placeholders
document.querySelectorAll('[data-placeholder-en]').forEach(input => {
const placeholder = input.getAttribute(`data-placeholder-${lang}`);
if (placeholder) {
input.placeholder = placeholder;
}
});
// Update language button states
document.querySelectorAll('.lang-btn').forEach(btn => {
btn.classList.toggle('active', btn.getAttribute('data-lang') === lang);
});
// Store preference
localStorage.setItem('preferredLanguage', lang);
}
// Language button event listeners
document.querySelectorAll('.lang-btn').forEach(btn => {
btn.addEventListener('click', () => {
const lang = btn.getAttribute('data-lang');
switchLanguage(lang);
});
});
// Load saved language preference
window.addEventListener('DOMContentLoaded', () => {
const savedLang = localStorage.getItem('preferredLanguage') || 'en';
switchLanguage(savedLang);
});
// 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 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');
});
});
// Smooth Scroll 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 offsetTop = target.offsetTop - 80; // Account for fixed navbar
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
// Navbar Background on Scroll
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 100) {
navbar.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.1)';
navbar.style.background = 'rgba(255, 255, 255, 0.98)';
} else {
navbar.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
navbar.style.background = '#ffffff';
}
});
// Form Submission Handler
const contactForm = document.querySelector('.contact-form form');
if (contactForm) {
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
// Get form data
const formData = new FormData(contactForm);
// Here you would typically send the data to a server
// For now, we'll just show a success message
alert('Thank you for your message! We will get back to you soon.');
// Reset form
contactForm.reset();
});
}
// Intersection Observer for 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 cards
document.querySelectorAll('.service-card, .why-card, .testimonial-card, .stat').forEach(card => {
card.style.opacity = '0';
card.style.transform = 'translateY(30px)';
card.style.transition = 'opacity 0.6s ease-out, transform 0.6s ease-out';
observer.observe(card);
});
// Counter Animation for Stats
const animateCounter = (element, target, duration = 2000) => {
let current = 0;
const increment = target / (duration / 16); // 60 FPS
const isPercentage = element.textContent.includes('%');
const hasPlus = element.textContent.includes('+');
const timer = setInterval(() => {
current += increment;
if (current >= target) {
current = target;
clearInterval(timer);
}
element.textContent = Math.floor(current) + (isPercentage ? '%' : '') + (hasPlus ? '+' : '');
}, 16);
};
// Observe stats for counter animation
const statsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const statElement = entry.target.querySelector('h4');
const text = statElement.textContent;
const number = parseInt(text.replace(/\D/g, ''));
if (number) {
animateCounter(statElement, number);
statsObserver.unobserve(entry.target);
}
}
});
}, { threshold: 0.5 });
document.querySelectorAll('.stat').forEach(stat => {
statsObserver.observe(stat);
});
// Add active state to navigation based on scroll position
window.addEventListener('scroll', () => {
const sections = document.querySelectorAll('section[id]');
const scrollY = window.pageYOffset;
sections.forEach(section => {
const sectionHeight = section.offsetHeight;
const sectionTop = section.offsetTop - 100;
const sectionId = section.getAttribute('id');
const navLink = document.querySelector(`.nav-menu a[href="#${sectionId}"]`);
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
if (navLink && !navLink.classList.contains('btn-nav')) {
document.querySelectorAll('.nav-menu a:not(.btn-nav):not(.lang-btn)').forEach(link => {
link.style.color = '';
});
navLink.style.color = '#2ba8c5';
}
}
});
});
// Parallax effect for hero section
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
if (hero && scrolled < window.innerHeight) {
hero.style.transform = `translateY(${scrolled * 0.5}px)`;
}
});
// Add hover effect to service cards
document.querySelectorAll('.service-card').forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-10px)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0)';
});
});
console.log('Hani-Haham.com website loaded successfully!');