-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
163 lines (113 loc) · 4.39 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// ==================================================
// Creating a responsive navbar
// ==================================================
const mobile_nav = document.querySelector(".mobile-navbar-btn");
const headerElem = document.querySelector(".header");
mobile_nav.addEventListener("click", () => {
headerElem.classList.toggle("active");
});
// ========================================
// sticky navigation
// ========================================
const heroSection = document.querySelector(".section-hero");
const observer = new IntersectionObserver(
(entries) => {
const ent = entries[0];
console.log(ent);
!ent.isIntersecting
? document.body.classList.add("sticky")
: document.body.classList.remove("sticky");
},
{
// viewport
root: null,
threshold: 0,
// rootMargin: "-100px",
}
);
observer.observe(heroSection);
// ==================================================
// Creating a portfolio tabbed CompositionEvent
// ==================================================
const p_btns = document.querySelector(".p-btns");
const p_btn = document.querySelectorAll(".p-btn");
const p_img_elem = document.querySelectorAll(".img-overlay");
p_btns.addEventListener("click",(e)=>{
const p_btn_clicked = e.target;
console.log(p_btn_clicked);
p_btn.forEach((curElem) => curElem.classList.remove("p-btn-active"));
p_btn_clicked.classList.add("p-btn-active");
//to find number in data attributes
const btn_num = p_btn_clicked.dataset.btnNum;
console.log(btn_num);
const img_active = document.querySelectorAll(`.p-btn--${btn_num}`)
p_img_elem.forEach((curElem) => curElem.classList.add("p-image-not-active"));
img_active.forEach((curElem) =>
curElem.classList.remove("p-image-not-active")
);
});
// ==================================================
// Scroll to top button section
// ==================================================
//without HTML
// const heroSection = document.querySelector(".section-hero");
const footerElem = document.querySelector(".section-footer");
const scroollElement = document.createElement("div");
scroollElement.classList.add("scrollTop-style");
scroollElement.innerHTML = `<ion-icon name="arrow-up-outline" class="scroll-top"></ion-icon>`;
footerElem.after(scroollElement);
const scrollTop =() =>{
heroSection.scrollIntoView({behavior:"smooth"});
};
scroollElement.addEventListener("click",scrollTop);
// ==================================================
// Animated numbers
// ==================================================
// const workSection = document.querySelector(".section-work-data");
// const workSectionObserve = (entries) => {
// const [entry] = entries;
// if (!entry.isIntersecting) return;
// console.log(entries);
// const counterNum = document.querySelectorAll(".counter-number");
// // console.log(counterNum);
// const speed = 200;
// counterNum.forEach((curNumber) => {
// const updateNumber = () => {
// const targetNumber = parseInt(curNumber.dataset.number);
// // console.log(targetNumber);
// const initialNumber = parseInt(curNumber.innerText);
// // console.log(initialNumber);
// const incrementNumber = Math.trunc(targetNumber / speed);
// // i am adding the value to the main number
// // console.log(incrementNumber);
// if (initialNumber < targetNumber) {
// curNumber.innerText = `${initialNumber + incrementNumber}+`;
// setTimeout(updateNumber, 10);
// } else {
// curNumber.innerText = `${targetNumber}+`;
// }
// };
// updateNumber();
// });
// };
// const workSecObserver = new IntersectionObserver(workSectionObserve, {
// root: null,
// threshold: 0,
// });
// workSecObserver.observe(workSection);
// Dark-Light mode
var icon = document.getElementById('sun-moon');
icon.classList.add('sun');
icon.addEventListener('click', ()=>{
document.body.classList.toggle('light')
if(document.body.classList.contains('light')){
icon.src="images/moon.png"
icon.classList.remove('sun');
icon.classList.add('margine');
}
else{
icon.src="images/sun.png"
icon.classList.add('sun');
icon.classList.remove('margine');
}
})