-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
71 lines (51 loc) · 2.26 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
// javascript for container
document.addEventListener("DOMContentLoaded", function () {
const menuIcon = document.getElementById("menuIcon");
const contentList = document.getElementById("contentList");
const contentDisplay = document.getElementById("contentDisplay");
menuIcon.addEventListener("click", () => {
const isMenuHidden = contentList.style.transform === "translateX(-100%)";
if (isMenuHidden) {
contentList.style.transform = "translateX(0)";
contentDisplay.style.marginLeft = "200px";
} else {
contentList.style.transform = "translateX(-100%)";
contentDisplay.style.marginLeft = "0";
}
});
const contentItems = document.querySelectorAll(".content-item");
contentItems.forEach((item) => {
item.addEventListener("click", () => {
const contentId = item.getAttribute("data-content");
// Hide all content
document.querySelectorAll(".content").forEach((content) => {
content.style.display = "none";
});
// Show the selected content
const selectedContent = document.getElementById(contentId);
if (selectedContent) {
selectedContent.style.display = "block";
}
});
});
// Show the initial content
document.getElementById("content1").style.display = "block";
});
// javascript for navbar
// Initially show the first section
const firstSection = document.getElementById("section1");
firstSection.style.display = "block";
// Add a click event listener to each navbar link
document.querySelectorAll("nav a").forEach((link) => {
link.addEventListener("click", (e) => {
e.preventDefault(); // Prevent the default behavior of the link
const targetId = link.getAttribute("href").substring(1); // Get the target section's ID
const targetSection = document.getElementById(targetId);
// Hide all sections
document.querySelectorAll("div[id^='section']").forEach((section) => {
section.style.display = "none";
});
// Show the target section
targetSection.style.display = "block";
});
});