-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
305 lines (235 loc) · 8.74 KB
/
main.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//Select Setting Box
let setting_box = document.querySelector(".setting-box")
let gear_icon = document.querySelector(".fa-gear")
gear_icon.onclick = function () {
setting_box.classList.toggle("open")
//toggle spin class on icon
gear_icon.classList.toggle("fa-spin")
}
//////////////////////////////////////////////
//change main-color
let lis = document.querySelectorAll(".colors-list li")
let arrayLis = Array.from(lis)
arrayLis.forEach((li) => {
li.addEventListener("click", (e) => {
//Switch colors of body
document.body.style.setProperty("--main-color", e.target.dataset.color)
// set color on local storage
localStorage.setItem("color_option", e.target.dataset.color)
//remove class active from lis
handleActive(e);
});
});
//Local Storage and Colors(check if there is local sotrage color option)
let mainColors = localStorage.getItem("color_option")
if (mainColors !== null) {
document.body.style.setProperty("--main-color", mainColors)
//remove active class from all colors list item
arrayLis.forEach((li) => {
li.classList.remove("active")
//add active class on element with data color == local storage item
if (li.dataset.color == mainColors) {
//add active class then
li.classList.add("active")
}
})
}
//////////////////////////////////////////////
//Get Array of imgs
let imgArr = ["bg1.jpg", "bg2.jpg", "bg3.png", "bg4.jpg", "bg5.jpg", "bg6.jpg"]
//background Option
let bgOption = true
//variable to control the bg interval
let bgInterval;
let landing_page = document.querySelector(".landing-page")
//function to randomize imgs
function randomizeImg() {
if (bgOption === true) {
bgInterval = setInterval(() => {
// Get random number
let randomNumber = Math.floor(Math.random() * imgArr.length)
//change bg
landing_page.style.backgroundImage = 'url("Imgs/'+imgArr[randomNumber] +'")'
//local storage BackGround
localStorage.setItem("bg", imgArr[randomNumber])
}, 10000);
}
}
//change Background Random Option
let randomBgsEl = document.querySelectorAll(".random-bgs span")
randomBgsEl.forEach((span) => {
span.addEventListener("click", (e) => {
handleActive(e);
if (e.target.dataset.bg === "yes") {
bgOption = true
randomizeImg()
localStorage.setItem("bgOption_item",true)
} else {
bgOption = false
clearInterval(bgInterval)
localStorage.setItem("bgOption_item",false)
}
});
});
//bgOption local storage
let bgLocalStorageOption= localStorage.getItem("bgOption_item")
if (bgLocalStorageOption !== null) {
//remove active classes from all spans
document.querySelectorAll(".random-bgs span").forEach((element) => {
element.classList.remove("active");
});
if (bgLocalStorageOption === "true") {
bgOption = true
document.querySelector(".yes").classList.add("active")
} else {
bgOption = false
document.querySelector(".no").classList.add("active")
}
}
let active = localStorage.getItem("bg")
if (active !== null) {
landing_page.style.backgroundImage = 'url("Imgs/'+active+'")'
}
randomizeImg();
//////////////////////////////////////////////
// Animate Skills When Reaching The Section
window.onscroll = function () {
let allSkills = document.querySelectorAll(".skill-box .skill-progress span")
if (scrollY >= 660) {
allSkills.forEach((skill) => {
skill.style.width = skill.dataset.progress;
})
}
}
//////////////////////////////////////////////
//create pop up with images in gallery
let ourGallery = document.querySelectorAll(".imgs-box img")
ourGallery.forEach((img) => {
img.addEventListener("click", (e)=> {
//create overlay element
let overlay = document.createElement("div")
//add class to overlay
overlay.className = "popup-overlay"
//append overlay to the body
document.body.appendChild(overlay)
//create the popUp box
let popupBox = document.createElement("div");
//add class to the box up box
popupBox.className = "popup-box"
if (img.alt !== null) {
// create heading
let imgHeading = document.createElement("h3")
// create text for heading
let imgText = document.createTextNode(img.alt)
// append text to the heading
imgHeading.appendChild(imgText)
//append imgHeading to popUp Box
popupBox.appendChild(imgHeading)
}
//create the img
let popupImg = document.createElement("img")
//set img source
popupImg.src = img.src
//put img inside pop up
popupBox.appendChild(popupImg)
//append the pop up box to the body
document.body.appendChild(popupBox)
//create the close span
let closeButton = document.createElement("span")
//create the close span text
let closeButtonText = document.createTextNode("X")
//append closeButtonText to close Button
closeButton.appendChild(closeButtonText)
//add class to the close button
closeButton.className = "close-button"
//append closeButton to the popUpBOx
popupBox.appendChild(closeButton)
})
})
//close popUp
document.addEventListener("click", (e) => {
if (e.target.className === "close-button") {
// Remove the popUp
console.log(e.target)
e.target.parentNode.remove()
//remove overlay (using another way of removing)
document.querySelector(".popup-overlay").remove()
}
})
//Navigation Bullets Design
//select all bullets
let bullets = document.querySelectorAll(".nav-bullets .bullet")
bullets.forEach((bullet) => {
bullet.addEventListener("click", (e) => {
document.querySelector(e.target.dataset.section).scrollIntoView({
behavior:'smooth'
})
})
})
//Bullets display
let bulletSpans = document.querySelectorAll(".Bullets-Option span")
let bulletsContainer = document.querySelector(".nav-bullets")
bulletSpans.forEach((span) => {
span.addEventListener("click", (e) => {
handleActive(e);
if (span.dataset.display === "show") {
bulletsContainer.style.display = "block"
localStorage.setItem('bulletOption', 'block')
} else {
bulletsContainer.style.display = "none"
localStorage.setItem('bulletOption', 'none')
}
})
})
let bulletLocalItem = localStorage.getItem("bulletOption")
if (bulletLocalItem !== null) {
bulletSpans.forEach((span) => {
span.classList.remove("active")
})
if (bulletLocalItem === "block") {
bulletsContainer.style.display = "block"
document.querySelector(".Bullets-Option .yes").classList.add("active")
} else {
bulletsContainer.style.display = "none"
document.querySelector(".Bullets-Option .no").classList.add("active")
}
}
//Create Handle Active Function
function handleActive(ev) {
//remove class active from all spans
ev.target.parentElement.querySelectorAll(".active").forEach((element) => {
element.classList.remove("active")
})
//add class active to the bgOption (yes or no)
ev.target.classList.add("active")
}
//Reset Button
document.querySelector(".setting-box button").onclick = function () {
localStorage.removeItem("color_option")
localStorage.removeItem("bgOption_item")
localStorage.removeItem("bulletOption")
window.location.reload(); //reload window
}
/////////////////////////////////////
// toggleMenu
let toggleMenueButton = document.querySelector(".toggle-menu")
let links = document.querySelector(".links")
toggleMenueButton.onclick = function (e) {
//stop propagation
e.stopPropagation()
this.classList.toggle("menu-active")
links.classList.toggle("open")
}
//click anywhere outside menu to close it
document.addEventListener("click", (e) => {
if (e.target !== toggleMenueButton && e.target !== links) {
if (links.classList.contains("open")) {
toggleMenueButton.classList.toggle("menu-active")
links.classList.toggle("open")
}
}
})
//stop propagation on menu
links.onclick = function (e) {
e.stopPropagation()
}