-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (73 loc) · 2.57 KB
/
Copy pathscript.js
File metadata and controls
84 lines (73 loc) · 2.57 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
// Mobile menu toggle
document.getElementById('mobile-menu-button').addEventListener('click', function () {
const menu = document.getElementById('mobile-menu');
menu.classList.toggle('hidden');
});
// FAQ toggle functionality
const faqToggles = document.querySelectorAll('.faq-toggle');
faqToggles.forEach(toggle => {
toggle.addEventListener('click', function () {
const content = this.nextElementSibling;
const icon = this.querySelector('i');
content.classList.toggle('hidden');
icon.style.transform = content.classList.contains('hidden') ? 'rotate(0deg)' : 'rotate(180deg)';
faqToggles.forEach(otherToggle => {
if (otherToggle !== toggle) {
otherToggle.nextElementSibling.classList.add('hidden');
otherToggle.querySelector('i').style.transform = 'rotate(0deg)';
}
});
});
});
// Contact form
document.getElementById('contactForm').addEventListener('submit', function (e) {
e.preventDefault();
alert(document.querySelector('[data-translate="form_thanks"]').textContent || 'Thank you for your message!');
this.reset();
});
// Smooth scroll
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
window.scrollTo({ top: target.offsetTop - 80, behavior: 'smooth' });
document.getElementById('mobile-menu')?.classList.add('hidden');
}
});
});
// Scroll-hide navbar 🧙♂️
let lastScrollTop = 0;
const navbar = document.querySelector('nav');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset || document.documentElement.scrollTop;
if (currentScroll > lastScrollTop) {
// Scrolling down
navbar.classList.add('navbar-hidden');
} else {
// Scrolling up
navbar.classList.remove('navbar-hidden');
}
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll;
});
// Language translation
const translations = {
en: {
home_title: "Sparkling Clean Spaces, Every Time",
home_button: "Get a Free Quote",
// ... (rest of translations)
},
de: {
home_title: "Strahlend saubere Räume, jedes Mal",
home_button: "Kostenloses Angebot anfordern",
// ... (rest of translations)
}
};
const userLang = navigator.language || navigator.userLanguage;
const lang = translations[userLang] ? userLang : 'en';
document.querySelectorAll('[data-translate]').forEach(el => {
const key = el.getAttribute('data-translate');
if (translations[lang][key]) {
el.textContent = translations[lang][key];
}
});