-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
164 lines (146 loc) · 5.99 KB
/
Copy pathscript.js
File metadata and controls
164 lines (146 loc) · 5.99 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
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
let slideIndex = 0;
showSlides();
function showSlides() {
let slides = document.getElementsByClassName("slide");
for (let i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1;
}
slides[slideIndex - 1].style.display = "block";
setTimeout(showSlides, 3000); // Change image every 3 seconds
}
function validateForm() {
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const interest = document.getElementById("interest").value;
if (name === "" || email === "" || interest === "") {
alert("All fields must be filled out");
return false;
}
return true;
}
function selectPackage(packageName) {
let packages = document.getElementsByClassName("package");
for (let i = 0; i < packages.length; i++) {
packages[i].classList.remove("selected");
}
const selectedPackage = document.querySelector(`[onclick="selectPackage('${packageName}')"]`);
if (selectedPackage) {
selectedPackage.classList.add("selected");
}
// Change the background image of the "Our Package" section
let packageSection = document.getElementById('packages');
console.log(`Changing background for: ${packageName}`); // Add debugging information
switch(packageName) {
case 'Raja Ampat':
packageSection.style.backgroundImage = "url('assets/img/raja_ampat.jpg')";
break;
case 'Banda Neira':
packageSection.style.backgroundImage = "url('assets/img/banda_neira.jpg')";
break;
case 'Bromo':
packageSection.style.backgroundImage = "url('assets/img/bromo.png')";
break;
case 'Bali':
packageSection.style.backgroundImage = "url('assets/img/bali.png')";
break;
default:
packageSection.style.backgroundImage = "none";
}
console.log(`Background image set to: ${packageSection.style.backgroundImage}`); // Add debugging information
}
// Smooth scrolling for navigation
document.querySelectorAll('nav ul li a').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
// Mark the current anchor as active
document.querySelectorAll('nav ul li a').forEach(link => link.classList.remove('active'));
this.classList.add('active');
});
});
document.addEventListener("DOMContentLoaded", function () {
// Function to handle form validation
function validateForm() {
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const interest = document.getElementById("interest").value;
if (name === "" || email === "" || interest === "") {
alert("All fields must be filled out");
return false;
}
return true;
}
// Function to handle package selection
function selectPackage(packageName) {
let packages = document.getElementsByClassName("package");
for (let i = 0; i < packages.length; i++) {
packages[i].classList.remove("selected");
}
const selectedPackage = document.querySelector(`[onclick="selectPackage('${packageName}')"]`);
if (selectedPackage) {
selectedPackage.classList.add("selected");
}
// Change the background image of the "Our Package" section
let packageSection = document.getElementById('packages');
switch(packageName) {
case 'Raja Ampat':
packageSection.style.backgroundImage = "url('assets/img/raja_ampat.jpg')";
break;
case 'Banda Neira':
packageSection.style.backgroundImage = "url('assets/img/banda_neira.jpg')";
break;
case 'Bromo':
packageSection.style.backgroundImage = "url('assets/img/bromo.png')";
break;
case 'Bali':
packageSection.style.backgroundImage = "url('assets/img/bali.png')";
break;
default:
packageSection.style.backgroundImage = "none";
}
}
// Function to handle scroll and update active nav link
function handleScroll(entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting) {
const id = entry.target.id;
document.querySelectorAll("nav ul li a").forEach(link => {
link.classList.remove("active");
if (link.getAttribute("href").substring(1) === id) {
link.classList.add("active");
}
});
}
});
}
// Setup Intersection Observer
const options = {
threshold: 0.5 // Adjust this value as needed
};
const observer = new IntersectionObserver(handleScroll, options);
// Observe each section
document.querySelectorAll("section").forEach(section => {
observer.observe(section);
});
// Smooth scrolling for navigation
document.querySelectorAll('nav ul li a').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
// Mark the current anchor as active
document.querySelectorAll('nav ul li a').forEach(link => link.classList.remove('active'));
this.classList.add('active');
});
});
// Export functions to global scope for HTML onclick attributes
window.selectPackage = selectPackage;
window.validateForm = validateForm;
});