Spaces:
Running
Running
File size: 7,243 Bytes
6be2b80 |
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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
document.addEventListener("DOMContentLoaded", () => {
// Mobile Menu Toggle
const mobileMenuBtn = document.querySelector(".mobile-menu-btn")
const navMenu = document.querySelector("nav ul")
if (mobileMenuBtn) {
mobileMenuBtn.addEventListener("click", () => {
navMenu.classList.toggle("active")
mobileMenuBtn.classList.toggle("active")
})
}
// Sticky Header
const header = document.querySelector("header")
window.addEventListener("scroll", () => {
if (window.scrollY > 50) {
header.style.background = "rgba(6, 16, 24, 0.95)"
header.style.boxShadow = "0 5px 15px rgba(0, 0, 0, 0.1)"
} else {
header.style.background = "rgba(6, 16, 24, 0.9)"
header.style.boxShadow = "none"
}
})
// Testimonial Slider
const testimonialTrack = document.querySelector(".testimonial-track")
const testimonials = document.querySelectorAll(".testimonial")
const prevBtn = document.querySelector(".prev-btn")
const nextBtn = document.querySelector(".next-btn")
const dotsContainer = document.querySelector(".slider-dots")
if (testimonialTrack && testimonials.length > 0) {
let currentIndex = 0
let slideWidth = testimonials[0].offsetWidth
let slidesToShow = 1
// Responsive slidesToShow
function updateSlidesToShow() {
if (window.innerWidth >= 1024) {
slidesToShow = 3
} else if (window.innerWidth >= 768) {
slidesToShow = 2
} else {
slidesToShow = 1
}
updateSlider()
}
// Create dots
function createDots() {
dotsContainer.innerHTML = ""
const totalDots = Math.ceil(testimonials.length / slidesToShow)
for (let i = 0; i < totalDots; i++) {
const dot = document.createElement("div")
dot.classList.add("dot")
if (i === 0) dot.classList.add("active")
dot.addEventListener("click", () => {
goToSlide(i)
})
dotsContainer.appendChild(dot)
}
}
// Update slider position
function updateSlider() {
slideWidth = testimonials[0].offsetWidth
testimonialTrack.style.transform = `translateX(-${currentIndex * slideWidth * slidesToShow}px)`
// Update dots
const dots = document.querySelectorAll(".dot")
dots.forEach((dot, index) => {
dot.classList.toggle("active", index === Math.floor(currentIndex / slidesToShow))
})
}
// Go to specific slide
function goToSlide(index) {
currentIndex = index
updateSlider()
}
// Next slide
function nextSlide() {
if (currentIndex < Math.ceil(testimonials.length / slidesToShow) - 1) {
currentIndex++
} else {
currentIndex = 0
}
updateSlider()
}
// Previous slide
function prevSlide() {
if (currentIndex > 0) {
currentIndex--
} else {
currentIndex = Math.ceil(testimonials.length / slidesToShow) - 1
}
updateSlider()
}
// Event listeners
if (nextBtn) nextBtn.addEventListener("click", nextSlide)
if (prevBtn) prevBtn.addEventListener("click", prevSlide)
// Auto slide
let slideInterval = setInterval(nextSlide, 5000)
// Pause on hover
testimonialTrack.addEventListener("mouseenter", () => {
clearInterval(slideInterval)
})
testimonialTrack.addEventListener("mouseleave", () => {
slideInterval = setInterval(nextSlide, 5000)
})
// Initialize
window.addEventListener("resize", () => {
updateSlidesToShow()
createDots()
})
updateSlidesToShow()
createDots()
}
// Animated Counter
const statNumbers = document.querySelectorAll(".stat-number")
function animateCounter(el) {
const target = Number.parseInt(el.getAttribute("data-count"))
const duration = 2000 // 2 seconds
const step = target / (duration / 16) // 60fps
let current = 0
const timer = setInterval(() => {
current += step
if (current >= target) {
clearInterval(timer)
el.textContent = target
} else {
el.textContent = Math.floor(current)
}
}, 16)
}
// Intersection Observer for counter animation
const observerOptions = {
threshold: 0.5,
}
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
animateCounter(entry.target)
observer.unobserve(entry.target)
}
})
}, observerOptions)
statNumbers.forEach((number) => {
observer.observe(number)
})
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault()
const targetId = this.getAttribute("href")
if (targetId === "#") return
const targetElement = document.querySelector(targetId)
if (targetElement) {
// Close mobile menu if open
if (navMenu.classList.contains("active")) {
navMenu.classList.remove("active")
mobileMenuBtn.classList.remove("active")
}
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: "smooth",
})
}
})
})
// Form submission
const recoveryForm = document.getElementById("recovery-form")
if (recoveryForm) {
recoveryForm.addEventListener("submit", function (e) {
e.preventDefault()
// Simulate form submission
const submitButton = this.querySelector(".submit-button")
submitButton.textContent = "Submitting..."
submitButton.disabled = true
// Simulate API call
setTimeout(() => {
alert("Thank you for your submission! Our recovery specialists will contact you shortly.")
this.reset()
submitButton.textContent = "Submit Recovery Request"
submitButton.disabled = false
}, 1500)
})
}
// Floating CTA button animation
const floatingBtn = document.querySelector(".floating-button")
if (floatingBtn) {
setInterval(() => {
floatingBtn.classList.add("pulse")
setTimeout(() => {
floatingBtn.classList.remove("pulse")
}, 1000)
}, 3000)
floatingBtn.addEventListener("click", () => {
document.querySelector("#contact").scrollIntoView({
behavior: "smooth",
block: "start",
})
})
}
// Add active class to nav links based on scroll position
const sections = document.querySelectorAll("section[id]")
const navLinks = document.querySelectorAll("nav ul li a")
function highlightNavLink() {
const scrollPosition = window.scrollY + 100
sections.forEach((section) => {
const sectionTop = section.offsetTop
const sectionHeight = section.offsetHeight
const sectionId = section.getAttribute("id")
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
navLinks.forEach((link) => {
link.classList.remove("active")
if (link.getAttribute("href") === `#${sectionId}`) {
link.classList.add("active")
}
})
}
})
}
window.addEventListener("scroll", highlightNavLink)
// Initial call to set active link
highlightNavLink()
})
|