-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
135 lines (114 loc) · 4.25 KB
/
Copy pathscript.js
File metadata and controls
135 lines (114 loc) · 4.25 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
// ============ NAVBAR SCROLL EFFECT ============
const navbar = document.getElementById('navbar');
window.addEventListener('scroll', () => {
navbar.classList.toggle('scrolled', window.scrollY > 20);
});
// ============ MOBILE MENU ============
const hamburger = document.getElementById('hamburger');
const navLinks = document.getElementById('navLinks');
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('open');
hamburger.setAttribute('aria-expanded', navLinks.classList.contains('open'));
});
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => navLinks.classList.remove('open'));
});
// ============ SCROLL ANIMATIONS ============
const animatedEls = document.querySelectorAll(
'.service-card, .product-card, .step, .why-card, .supplier-feature, .about-point, .coa-highlight'
);
animatedEls.forEach(el => el.classList.add('fade-in'));
const observer = new IntersectionObserver(
entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.08, rootMargin: '0px 0px -30px 0px' }
);
animatedEls.forEach(el => observer.observe(el));
// ============ ACTIVE NAV LINK ON SCROLL ============
const sections = document.querySelectorAll('section[id]');
const navAnchors = document.querySelectorAll('.nav-links a[href^="#"]');
const activeStyle = document.createElement('style');
activeStyle.textContent = '.nav-links a.active { color: var(--green-700) !important; font-weight: 600; }';
document.head.appendChild(activeStyle);
const sectionObserver = new IntersectionObserver(
entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const id = entry.target.id;
navAnchors.forEach(a => {
a.classList.toggle('active', a.getAttribute('href') === `#${id}`);
});
}
});
},
{ threshold: 0.25 }
);
sections.forEach(s => sectionObserver.observe(s));
// ============ CONTACT FORM ============
const form = document.getElementById('contactForm');
const submitBtn = document.getElementById('submitBtn');
const formSuccess = document.getElementById('formSuccess');
if (form) {
form.addEventListener('submit', e => {
e.preventDefault();
const required = form.querySelectorAll('[required]');
let valid = true;
required.forEach(field => {
field.style.borderColor = '';
const isEmpty = field.type === 'checkbox' ? !field.checked : !field.value.trim();
if (isEmpty) {
if (field.type !== 'checkbox') field.style.borderColor = '#ef4444';
valid = false;
}
});
if (!valid) return;
const btnText = submitBtn.querySelector('.btn-text');
const btnLoading = submitBtn.querySelector('.btn-loading');
submitBtn.disabled = true;
btnText.style.display = 'none';
btnLoading.style.display = 'inline';
const data = new FormData(form);
fetch('https://api.web3forms.com/submit', {
method: 'POST',
body: data
})
.then(res => res.json())
.then(json => {
if (json.success) {
submitBtn.style.display = 'none';
formSuccess.style.display = 'flex';
form.reset();
} else {
btnText.style.display = 'inline';
btnLoading.style.display = 'none';
submitBtn.disabled = false;
alert('Something went wrong. Please try again or contact us directly via WhatsApp.');
}
})
.catch(() => {
btnText.style.display = 'inline';
btnLoading.style.display = 'none';
submitBtn.disabled = false;
alert('Network error. Please check your connection or contact us via WhatsApp.');
});
});
form.querySelectorAll('input, select, textarea').forEach(field => {
field.addEventListener('input', () => { field.style.borderColor = ''; });
});
}
// ============ SMOOTH ANCHOR SCROLLING ============
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', e => {
const target = document.querySelector(anchor.getAttribute('href'));
if (!target) return;
e.preventDefault();
const top = target.getBoundingClientRect().top + window.scrollY - 76;
window.scrollTo({ top, behavior: 'smooth' });
});
});