forked from apu52/Travel_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
140 lines (106 loc) · 3.9 KB
/
index.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
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
// Modal JS
const modalContainer = document.querySelector(".modal-container");
const closeBtn = document.querySelector(".close-btn");
const subscribeBtn = document.querySelector("#news-subscribe");
const form = document.querySelector("#modal-form");
function openModal() {
modalContainer.style.display = "flex";
}
function closeModal() {
modalContainer.style.display = "none";
}
// Function to handle form submission (you can customize this)
function subscribe(e) {
e.preventDefault();
const emailInput = document.querySelector("#modal-email").value;
// You can add your logic to handle the form submission here
// alert("Email subscribed: " + emailInput);
closeModal();
}
// Close the modal when clicking outside the modal content (new code)
window.addEventListener("click", (e) => {
if (e.target === modalContainer) {
closeModal();
}
});
// Close the modal when clicking the exit button (new code)
closeBtn.addEventListener("click", closeModal);
form.addEventListener("submit", subscribe);
closeBtn.addEventListener("click", closeModal);
// Open the modal as soon as the page loads
window.onload = openModal;
// carousel JS
const slideDots = document.querySelectorAll(".imageDots span");
const slides = document.querySelectorAll(".mySlides");
activeSlide = 0;
slideInterval=null;
const destinationTitles = [
"Eiffel Tower",
"Giant Wheel",
"Goa Beach",
"Male Beach",
];
const destinationSubtitles = ["Paris", "London", "Goa", "Maldives"];
slideDots.forEach((dot, index) => {
dot.addEventListener("click", () => {
changeSlide(null, index);
});
});
document.querySelector(".destination__nav span:nth-child(1)").addEventListener("click", () => {
changeSlide(-1, null);
resetSlideInterval();
});
document.querySelector(".destination__nav span:nth-child(2)").addEventListener("click", () => {
changeSlide(1, null);
resetSlideInterval();
});
function changeSlide(relativeNum, absoluteNum) {
if (typeof relativeNum === "number") {
activeSlide = (activeSlide + relativeNum) % slides.length;
if (activeSlide < 0) activeSlide = slides.length + activeSlide;
} else if (typeof absoluteNum === "number") {
activeSlide = absoluteNum;
}
const title = destinationTitles[activeSlide];
const subtitle = destinationSubtitles[activeSlide];
slides.forEach((slide, index) => {
if (!slide.querySelector(".destination__details")) {
const detailsContainer = document.createElement("div");
detailsContainer.className = "destination__details";
slide.appendChild(detailsContainer);
const titleElement = document.createElement("p");
titleElement.className = "destination__title";
detailsContainer.appendChild(titleElement);
const subtitleElement = document.createElement("p");
subtitleElement.className = "destination__subtitle";
detailsContainer.appendChild(subtitleElement);
}
const titleElement = slide.querySelector(".destination__title");
const subtitleElement = slide.querySelector(".destination__subtitle");
titleElement.textContent = title;
subtitleElement.textContent = subtitle;
});
slides[0].style.marginLeft = `${-activeSlide * 100}%`;
slideDots.forEach((dot) => {
dot.classList.remove("active");
});
slideDots[activeSlide].classList.add("active");
}
function startSlideInterval() {
slideInterval = setInterval(() => {
changeSlide(1, null);
}, 4000); // Change slide every 4 seconds
}
function resetSlideInterval() {
clearInterval(slideInterval); // For clearing auto- slide
startSlideInterval(); // initializing the auto - slide
}
// Initial details rendering
changeSlide(0);
startSlideInterval();
document.getElementById('emailInput').addEventListener('focus', function() {
document.getElementById('send').classList.add('focused');
});
document.getElementById('emailInput').addEventListener('blur', function() {
document.getElementById('send').classList.remove('focused');
});