-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathmain.js
193 lines (157 loc) · 4.88 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
// change navbar styles on scroll
/*window.addEventListener("scroll", () => {
document
.querySelector("nav")
.classList.toggle("window-scroll", window.scrollY > 0);
});*/
// Get the navbar element
const navbar = document.querySelector('.navbar');
const scrollBtn=document.getElementById("progress-value")
console.log(scrollBtn)
// Add an event listener to the scroll event
window.addEventListener('scroll', () => {
// Check if the scroll position is greater than a certain threshold
if (window.scrollY > 0) {
// Add the "window-scroll" class to the navbar
navbar.classList.add('window-scroll');
scrollBtn.style.visibility="visible"
} else {
// Remove the "window-scroll" class from the navbar
navbar.classList.remove('window-scroll');
scrollBtn.style.visibility="hidden"
}
});
//for initial render icon hide
document.addEventListener('DOMContentLoaded', function() {
if (window.scrollY > 0) {
scrollBtn.style.visibility="visible"
} else {
// Remove the "window-scroll" class from the navbar
scrollBtn.style.visibility="hidden"
}
});
// show/hide faq answer
const faqs = document.querySelectorAll(".faq");
faqs.forEach((faq) => {
faq.addEventListener("click", () => {
faq.classList.toggle("open");
// change icon
const icon = faq.querySelector(".faq__icon i");
if (icon.className === "uil uil-plus") {
icon.className = "uil uil-minus";
} else {
icon.className = "uil uil-plus";
}
});
});
// show/hide nav menu
const menu = document.querySelector(".nav__menu");
const menuBtn = document.querySelector("#open-menu-btn");
const closeBtn = document.querySelector("#close-menu-btn");
menuBtn.addEventListener("click", () => {
menu.style.display = "flex";
closeBtn.style.display = "inline-block";
menuBtn.style.display = "none";
});
// close nav menu
const closeNav = () => {
menu.style.display = "none";
closeBtn.style.display = "none";
menuBtn.style.display = "inline-block";
};
closeBtn.addEventListener("click", closeNav);
// Start of Scroll-to-Top button
let calcScrollValue = () => {
let scrollProgress = document.getElementById("progress");
let progressValue = document.getElementById("progress-value");
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(#0077B5 ${scrollValue}%, #d7d7d7 ${scrollValue}%)`;
};
function scrolltotop(){
window.scroll ({
top:0,
behavior:"smooth"
});
}
//Pure counter
new PureCounter();
new PureCounter({
selector: ".purecounter",
start: 0,
end: 100,
duration: 2,
delay: 10,
once: true,
pulse: false,
decimals: 0,
legacy: true,
filesizing: false,
currency: false,
formater: "us-US",
separator: false,
});
window.onscroll = calcScrollValue;
window.onload = calcScrollValue;
// Clickable Copyright name
const copyright = document.querySelector(".footer__copyright small span");
copyright.addEventListener("click", function () {
window.open("https://github.com/aniketsinha2002?tab=repositories", "blank");
});
// Type Writer Effect -
var TxtType = function (el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = "";
this.tick();
this.isDeleting = false;
};
TxtType.prototype.tick = function () {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + "</span>";
var that = this;
var delta = 200 - Math.random() * 100;
if (this.isDeleting) {
delta /= 2;
}
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === "") {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function () {
that.tick();
}, delta);
};
window.onload = function () {
var elements = document.getElementsByClassName("typewrite");
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute("data-type");
var period = elements[i].getAttribute("data-period");
if (toRotate) {
new TxtType(elements[i], JSON.parse(toRotate), period);
}
}
};