Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
134 lines (124 loc) · 4.83 KB
/
Copy pathscript.js
File metadata and controls
134 lines (124 loc) · 4.83 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
document.addEventListener('DOMContentLoaded', function() {
// Hamburger menu toggle
const toggle = document.querySelector('.menu-toggle');
const navLinks = document.querySelector('.nav-links');
const menuIcon = document.querySelector('.menu-icon');
const closeIcon = document.querySelector('.close-icon');
const body = document.body;
if (toggle && navLinks && menuIcon && closeIcon) {
toggle.addEventListener('click', function() {
navLinks.classList.toggle('active');
const isOpen = navLinks.classList.contains('active');
menuIcon.style.display = isOpen ? 'none' : 'inline';
closeIcon.style.display = isOpen ? 'inline' : 'none';
// Lock or unlock body scroll
if (isOpen) {
body.classList.add('menu-open');
} else {
body.classList.remove('menu-open');
}
});
}
// Dropdown toggle for Services on mobile
const dropdownToggle = document.querySelector('.dropdown-toggle');
const dropdown = document.querySelector('.dropdown');
function isMobile() {
return window.innerWidth <= 768;
}
if (dropdownToggle && dropdown) {
dropdownToggle.addEventListener('click', function(e) {
if (isMobile()) {
e.preventDefault();
dropdown.classList.toggle('open');
}
});
}
// Optional: Close dropdown when resizing from mobile to desktop
window.addEventListener('resize', function() {
if (!isMobile() && dropdown) {
dropdown.classList.remove('open');
}
if (!isMobile() && navLinks) {
navLinks.classList.remove('active');
menuIcon.style.display = 'inline';
closeIcon.style.display = 'none';
}
});
// Animate .wrapper when it enters the viewport
const wrapper = document.querySelector('.wrapper');
function revealWrapperOnScroll() {
if (!wrapper) return;
const rect = wrapper.getBoundingClientRect();
const windowHeight = window.innerHeight || document.documentElement.clientHeight;
if (rect.top < windowHeight - 100) { // 100px before it fully enters
wrapper.classList.add('visible');
window.removeEventListener('scroll', revealWrapperOnScroll);
}
}
revealWrapperOnScroll();
window.addEventListener('scroll', revealWrapperOnScroll);
// Initialize international telephone input
var input = document.querySelector("#phone");
var errorMsg = document.querySelector("#phone-error");
var iti = window.intlTelInput(input, {
initialCountry: "auto",
geoIpLookup: function(callback) {
fetch('https://ipapi.co/json')
.then(res => res.json())
.then(data => callback(data.country_code))
.catch(() => callback('NG'));
},
utilsScript: "https://cdn.jsdelivr.net/npm/intl-tel-input@18.2.1/build/js/utils.js"
});
function validatePhone() {
if (input.value.trim()) {
if (iti.isValidNumber()) {
errorMsg.style.display = "none";
input.style.borderColor = "#ccc";
} else {
errorMsg.style.display = "block";
input.style.borderColor = "red";
}
} else {
errorMsg.style.display = "none";
input.style.borderColor = "#ccc";
}
}
input.addEventListener('blur', validatePhone);
input.addEventListener('change', validatePhone);
input.addEventListener('keyup', validatePhone);
// Optional: Prevent form submission if invalid
document.querySelector('.contact-form').addEventListener('submit', function(e) {
if (!iti.isValidNumber()) {
e.preventDefault();
errorMsg.style.display = "block";
input.style.borderColor = "red";
input.focus();
}
});
// Back to Top button functionality
const backToTop = document.getElementById('backToTop');
window.addEventListener('scroll', function() {
if (window.scrollY > 300) {
backToTop.style.display = 'block';
} else {
backToTop.style.display = 'none';
}
});
backToTop.addEventListener('click', function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
// Scroll-triggered reveal effect
const reveals = document.querySelectorAll('.reveal');
function revealOnScroll() {
const windowHeight = window.innerHeight;
reveals.forEach(section => {
const sectionTop = section.getBoundingClientRect().top;
if (sectionTop < windowHeight - 80) {
section.classList.add('visible');
}
});
}
window.addEventListener('scroll', revealOnScroll);
revealOnScroll();
});