-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
116 lines (94 loc) · 3.76 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
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
document.addEventListener("DOMContentLoaded", function () {
const slides = document.querySelector(".slides");
const slideWidth = slides.clientWidth;
const dotsContainer = document.querySelector(".dots");
const dots = [];
const arrows = document.querySelectorAll(".arrow");
// Create dots
for (let i = 0; i < slides.children.length; i++) {
const dot = document.createElement("div");
dot.classList.add("dot");
dotsContainer.appendChild(dot);
dots.push(dot);
dot.addEventListener("click", function () {
goToSlide(i);
});
}
dots[0].classList.add("active");
let currentIndex = 0;
function goToSlide(index) {
if (
index < 0 ||
index >= slides.children.length ||
index === currentIndex
) {
return;
}
slides.style.transform = `translateX(-${index * slideWidth}px)`;
dots[currentIndex].classList.remove("active");
dots[index].classList.add("active");
currentIndex = index;
}
function nextSlide() {
const nextIndex = (currentIndex + 1) % slides.children.length;
goToSlide(nextIndex);
}
function prevSlide() {
const prevIndex =
(currentIndex - 1 + slides.children.length) % slides.children.length;
goToSlide(prevIndex);
}
arrows.forEach((arrow) => {
arrow.addEventListener("click", function () {
if (arrow.classList.contains("prev")) {
prevSlide();
} else if (arrow.classList.contains("next")) {
nextSlide();
}
});
});
setInterval(nextSlide, 5000); // Change slide every 3 seconds
});
document.addEventListener("DOMContentLoaded", function () {
// Get the navigation links
const homeLink = document.querySelector(".home-link");
const aboutLink = document.querySelector(".about-link");
const courseLink = document.querySelector(".course-link");
// Get the sections
const homeSection = document.getElementById("home-section");
const aboutSection = document.getElementById("about-section");
const courseSection = document.getElementById("course-section");
// Add click event listeners to the navigation links
homeLink.addEventListener("click", function (event) {
event.preventDefault(); // Prevent the default link behavior
// Option 1: Using scrollIntoView with behavior: smooth (modern browsers)
homeSection.scrollIntoView({ behavior: "smooth" });
// Option 2: Using a custom smooth scrolling function (for older browsers)
// You can find implementations of smooth scrolling functions online.
});
aboutLink.addEventListener("click", function (event) {
event.preventDefault(); // Prevent the default link behavior
aboutSection.scrollIntoView({ behavior: "smooth" });
});
courseLink.addEventListener("click", function (event) {
event.preventDefault(); // Prevent the default link behavior
courseSection.scrollIntoView({ behavior: "smooth" });
});
});
document.addEventListener("DOMContentLoaded", function () {
const messageForm = document.getElementById("message-form");
messageForm.addEventListener("submit", function (event) {
event.preventDefault(); // Prevent form submission
// Get the user's message
const message = document.getElementById("message").value;
// You can handle the message submission here, for example, send it to a server
// For demonstration purposes, let's just log the message to the console
console.log("User's Message:", message);
// Optionally, you can clear the textarea after submitting the message
document.getElementById("message").value = "";
});
});
const researchBox = document.getElementById("researchBox");
researchBox.addEventListener("click", () => {
researchBox.classList.toggle("expanded");
});