-
Notifications
You must be signed in to change notification settings - Fork 28
/
script.js
205 lines (153 loc) · 5.16 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
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
// active hamburger menu
let menuIcon = document.querySelector(".menu-icon");
let navlist = document.querySelector(".navlist")
menuIcon.addEventListener("click",()=>{
menuIcon.classList.toggle("active");
navlist.classList.toggle("active");
document.body.classList.toggle("open");
});
// remove navlist
navlist.addEventListener("click",()=>{
navlist.classList.remove("active");
menuIcon.classList.remove("active");
document.body.classList.remove("open");
})
// rotate text js code
let text = document.querySelector(".text p");
text.innerHTML = text.innerHTML.split("").map((char,i)=>
`<b style="transform:rotate(${i * 6.3}deg")>${char}</b>`
).join("");
// switch between about buttons
const buttons = document.querySelectorAll('.about-btn button');
const contents = document.querySelectorAll('.content');
buttons.forEach((button, index) => {
button.addEventListener('click', () => {
contents.forEach(content => content.style.display = 'none');
contents[index].style.display = 'block';
buttons.forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
});
});
// portfolio fillter
var mixer = mixitup('.portfolio-gallery',{
selectors: {
target: '.portfolio-box'
},
animation: {
duration: 500
}
});
// Initialize swiperjs
var swiper = new Swiper(".mySwiper", {
slidesPerView: 1,
spaceBetween: 30,
pagination: {
el: ".swiper-pagination",
clickable: true,
},
autoplay:{
delay:3000,
disableOnInteraction:false,
},
breakpoints: {
576:{
slidesPerView:2,
spaceBetween:10,
},
1200:{
slidesPerView:3,
spaceBetween:20,
},
}
});
// Swiper buttons
document.getElementById("prev-button").addEventListener("click", function () {
swiper.slidePrev();
});
document.getElementById("next-button").addEventListener("click", function () {
swiper.slideNext();
});
// skill Progress bar
const first_skill = document.querySelector(".skill:first-child");
const sk_counters = document.querySelectorAll(".counter span");
const progress_bars = document.querySelectorAll(".skills svg circle");
window.addEventListener("scroll",()=>{
if(!skillsPlayed)
skillsCounter();
})
function hasReached(el){
let topPosition = el.getBoundingClientRect().top;
if(window.innerHeight >= topPosition + el.offsetHeight)return true;
return false;
}
function updateCount(num,maxNum){
let currentNum = +num.innerText;
if(currentNum < maxNum){
num.innerText = currentNum + 1;
setTimeout(()=>{
updateCount(num,maxNum)
},12)
}
}
let skillsPlayed = false;
function skillsCounter(){
if(!hasReached(first_skill))return;
skillsPlayed = true;
sk_counters.forEach((counter,i)=>{
let target = +counter.dataset.target;
let strokeValue = 465 - 465 * (target / 100);
progress_bars[i].style.setProperty("--target",strokeValue);
setTimeout(()=>{
updateCount(counter,target);
},400)
});
progress_bars.forEach(p => p.style.animation = "progress 2s ease-in-out forwards");
}
// side progress bar
let calcScrollValue = ()=>{
let scrollProgress = document.getElementById("progress");
let pos = document.documentElement.scrollTop;
let calcHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
let scrollValue = Math.round((pos * 100)/calcHeight);
if(pos > 100){
scrollProgress.style.display = "grid";
}else{
scrollProgress.style.display = "none";
}
scrollProgress.addEventListener("click",()=>{
document.documentElement.scrollTop = 0;
});
scrollProgress.style.background = `conic-gradient(#fff ${scrollValue}%,#e6006d ${scrollValue}%)`;
};
window.onscroll = calcScrollValue;
window.onload = calcScrollValue;
// active menu
let menuLi = document.querySelectorAll("nav ul li a");
let section = document.querySelectorAll('section');
// add "our stats" navlist item to add active class to it
let navStats = document.querySelectorAll("nav ul li a[href='#contact']");
function activeMenu(){
let bodyHeight = document.body.offsetHeight;
let len = section.length;
while(--len && window.scrollY + 97 < section[len].offsetTop){}
menuLi.forEach(sec => sec.classList.remove("active"));
menuLi[len].classList.add("active");
// if scroll reaches bottom, add active class to "our stats"
if (pageYOffset + window.innerHeight >= bodyHeight) {
menuLi.forEach(sec => sec.classList.remove("active"));
navStats[0].classList.add("active");
}
}
activeMenu();
window.addEventListener("scroll",activeMenu);
// scroll reveal
ScrollReveal({
distance:"90px",
duration:2000,
delay:200,
// reset: true ,
});
ScrollReveal().reveal('.hero-info,.main-text,.proposal,.heading', { origin: "top" });
ScrollReveal().reveal('.about-img,.fillter-buttons,.contact-info', { origin: "left" });
ScrollReveal().reveal('.about-content,.skills', { origin: "right" });
ScrollReveal().reveal('.allServices,.portfolio-gallery,.blog-box,footer,.img-hero', { origin: "bottom" });