-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
149 lines (125 loc) · 4.73 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
let nav = document.querySelector(".nav-links");
let navList = document.createElement("ul");
navList.classList.add("menu");
// Creating the nav link (about)
let aboutList = document.createElement("li");
let aboutLink = document.createElement("a");
aboutLink.href = "javascript:void(0)";
aboutLink.id = "aboutId";
aboutLink.classList = "menuItem";
aboutLink.textContent = "About";
aboutList.appendChild(aboutLink);
navList.appendChild(aboutList);
nav.appendChild(navList);
// get the aboutLink id and about section id
let aboutLinkId = document.getElementById("aboutId");
let about = document.getElementById("about");
// adding the scroll function to the about link
addScroll(aboutLinkId, about);
// creating the nav link (services)
let servicesList = document.createElement("li");
let servicesLink = document.createElement("a");
servicesLink.href = "javascript:void(0)";
servicesLink.id = "servicesId";
servicesLink.classList = "menuItem";
servicesLink.textContent = "Services";
servicesList.appendChild(servicesLink);
navList.appendChild(servicesList);
nav.appendChild(navList);
// get the servicesLink and services section id
let servicesLinkId = document.getElementById("servicesId");
let services = document.getElementById("services");
// add scroll function to the services link
addScroll(servicesLinkId, services);
// creating the nav link (portfolio)
let portfolioList = document.createElement("li");
let portfolioLink = document.createElement("a");
portfolioLink.href = "javascript:void(0)";
portfolioLink.id = "portfolioId";
portfolioLink.classList = "menuItem";
portfolioLink.textContent = "Portfolio";
portfolioList.appendChild(portfolioLink);
navList.appendChild(portfolioList);
nav.appendChild(navList);
// get the portfolioLink and portfolio section id
let portfolioLinkId = document.getElementById("portfolioId");
let portfolio = document.getElementById("portfolio");
// add scroll function to services
addScroll(portfolioLinkId, portfolio);
// creating the nav link (team)
let teamList = document.createElement("li");
let teamLink = document.createElement("a");
teamLink.href = "javascript:void(0)";
teamLink.id = "teamId";
teamLink.classList = "menuItem";
teamLink.textContent = "Team";
teamList.appendChild(teamLink);
navList.appendChild(teamList);
nav.appendChild(navList);
// get the teamLink and team section id
let teamLinkId = document.getElementById("teamId");
let team = document.getElementById("team");
// add scroll function to team
addScroll(teamLinkId, team);
// creating the nav link (contact)
let contactList = document.createElement("li");
let contactLink = document.createElement("a");
contactLink.href = "javascript:void(0)";
contactLink.id = "contactId";
contactLink.classList = "menuItem";
contactLink.textContent = "Contact";
contactList.appendChild(contactLink);
navList.appendChild(contactList);
nav.appendChild(navList);
// get the contactLink and contact section id
let contactLinkId = document.getElementById("contactId");
let contact = document.getElementById("contact");
// add scroll function to contact
addScroll(contactLinkId, contact, contactLink);
// get the boundless logo and hero section id
let logo = document.getElementById("logo");
let hero = document.getElementById("hero");
// add scroll function to the hero section
addScroll(logo, hero);
// javascript to toggle nav menu
const menu = document.querySelector(".menu");
let menuItems = document.querySelectorAll(".menuItem");
const navToggle = document.querySelector(".nav-toggle");
const openIcon = document.querySelector(".open-icon");
const closeIcon = document.querySelector(".close-icon");
const current = document.querySelector(".active");
function toggleMenu() {
if (menu.classList.contains("show-menu")) {
menu.classList.remove("show-menu");
closeIcon.style.display = "none";
openIcon.style.display = "block";
} else {
menu.classList.add("show-menu");
closeIcon.style.display = "block";
openIcon.style.display = "none";
}
}
navToggle.addEventListener("click", toggleMenu);
// To close the menu when you click a nav link in mobile mode.
menuItems.forEach((menuItem) => {
menuItem.addEventListener("click", toggleMenu);
});
// the scroll function
function addScroll(linkId, sectionId) {
linkId.addEventListener("click", function () {
sectionId.scrollIntoView({ behavior: "smooth", block: "start" });
});
}
// function addScroll(linkId, sectionId, menuItems) {
// linkId.addEventListener("click", function() {
// let scrolled = sectionId.scrollIntoView({behavior: "smooth", block: "start"});
// return scrolled;
// });
// for (let i = 0; i < menuItems.length; i++) {
// if (scrolled){
// menuItems[i].classList.add(".active");
// } else {
// menuItems[i].classList.remove("active");
// }
// }
// }