-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
88 lines (76 loc) · 2.88 KB
/
script.js
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
// script.js
document.addEventListener('DOMContentLoaded', (event) => {
const menuToggle = document.querySelector('.menu-toggle');
const navUl = document.querySelector('nav ul');
if (menuToggle && navUl) {
menuToggle.addEventListener('click', () => {
navUl.classList.toggle('show');
});
}
document.addEventListener('DOMContentLoaded', (event) => {
// Smooth scrolling for navigation links
document.querySelectorAll('nav a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Mobile menu toggle
const menuToggle = document.querySelector('.menu-toggle');
const nav = document.querySelector('nav ul');
if (menuToggle && nav) {
menuToggle.addEventListener('click', () => {
nav.classList.toggle('show');
});
}
// Lazy loading images
const images = document.querySelectorAll('img[data-src]');
const options = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.removeAttribute('data-src');
imageObserver.unobserve(img);
}
});
}, options);
images.forEach(img => imageObserver.observe(img));
// Add animation to case studies when they come into view
const caseStudies = document.querySelectorAll('.case-study');
const caseStudyObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in');
caseStudyObserver.unobserve(entry.target);
}
});
}, { threshold: 0.1 });
caseStudies.forEach(study => caseStudyObserver.observe(study));
// Form validation for contact form (if exists)
const contactForm = document.querySelector('#contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Add your form validation logic here
console.log('Form submitted');
// You can add AJAX submission here
});
}
// Add custom tracking events
const ctaButtons = document.querySelectorAll('.cta-button');
ctaButtons.forEach(button => {
button.addEventListener('click', function(e) {
const buttonText = this.textContent;
// Replace with your actual tracking code
console.log(`CTA clicked: ${buttonText}`);
});
});
});