-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
95 lines (78 loc) · 2.53 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
// Open & Close HamMenu on Mobile
const hamParent = document.querySelector(".ham__container");
const hamMenu = document.querySelector(".ham-menu");
const hamMenuCross = document.querySelector(".ham__menu-cross");
hamMenu.addEventListener("click", function () {
hamParent.style.display = "block";
});
hamMenuCross.addEventListener("click", () => {
hamParent.style.display = "none";
});
// Adding Projects files
const container = document.querySelector(".project__container");
const images = ["images/project-img.png", "images/project-img.png"];
function newProject({ languages, name, oneLine }) {
let html = `
<div class="project__comp">
<img class="project__img" src="images/project-img.png" alt="Project" />
<p class="project__lang">${languages}</p>
<div class="project__description">
<h4 class="project__name cl-white">${name}</h4>
<p class="project__oneline">${oneLine}</p>
<div class="project__btns">
<button class="project__btn">Demo</button>
<button class="project__btn">Code</button>
</div>
</div>
</div>
`;
container.insertAdjacentHTML("beforeend", html);
}
newProject({
languages: "HTML JavaScript SCSS",
name: "News HomePage",
oneLine: "Responsive Landing Page",
});
newProject({
languages: "HTML Bootstrap JavaScript SCSS",
name: "News HomePage",
oneLine: "Responsive Landing Page",
});
// Using Intersection Observer Api for Active Nav Links
const sections = document.querySelectorAll(".section");
const navItem = document.querySelectorAll(".nav__item");
const hamContainer = document.querySelector(".ham__container");
const hamItem = document.querySelectorAll(".ham__item");
const options = {
threshold: "0.2",
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) {
return;
}
// Active Links For Large Screens
navItem.forEach((link) => {
link.classList.remove("cl-white");
if (entry.target.id === link.dataset.nav) {
link.classList.add("cl-white");
}
});
// Active Links For HamMenu Mobile Screens
hamItem.forEach((link) => {
link.classList.remove("cl-white");
if (entry.target.id === link.dataset.ham) {
link.classList.add("cl-white");
}
});
});
}, options);
sections.forEach((section) => {
observer.observe(section);
});
// Hiding HamMenu When Clicked on HamItems
hamItem.forEach((item) => {
item.addEventListener("click", () => {
hamContainer.style.display = "";
});
});