forked from aniketsinha2002/DataGeek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
184 lines (147 loc) · 5.49 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
// change navbar styles on scroll
window.addEventListener('scroll', () => {
document.querySelector('nav').classList.toggle('window-scroll', window.scrollY > 0)
})
// 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)
// Number counter animation
function animateCounter(counterElement, targetNumber, duration) {
const startNumber = parseInt(counterElement.innerText);
const increment = Math.ceil((targetNumber - startNumber) / (duration / 10));
let currentNumber = startNumber;
const timer = setInterval(() => {
currentNumber += increment;
counterElement.innerText = currentNumber;
// Check if the current number has reached or exceeded the target number
if ((increment > 0 && currentNumber >= targetNumber) || (increment < 0 && currentNumber <= targetNumber)) {
clearInterval(timer);
counterElement.innerText = targetNumber;
}
}, 10);
return timer;
}
function handleIntersection(entries, observer) {
entries.forEach((entry) => {
const counterElement = entry.target;
const targetNumber = parseInt(counterElement.dataset.target);
const duration = 2000;
if (entry.isIntersecting) {
counterElement.style.visibility = 'visible';
animateCounter(counterElement, targetNumber, duration);
observer.unobserve(counterElement);
} else {
counterElement.style.visibility = 'hidden';
}
});
}
//using IntersectionObserver to triggrt animation once element is visible on screen
const observer = new IntersectionObserver(handleIntersection);
const counters = document.querySelectorAll('.num_count');
counters.forEach((counterElement) => {
observer.observe(counterElement); // Observe each counter element
});
// **********************Adjust scroll height****************************
const navLinks = document.querySelectorAll(".nav__link");
navLinks.forEach((link) => {
link.addEventListener("click", (e) => {
// prevent default
e.preventDefault()
// select each link element by id
const id = e.currentTarget.getAttribute("href").slice(1)
let section = document.getElementById(id)
// calculate heights
const navHeight = document.querySelector("nav").getBoundingClientRect().height;
let scrollPosition = section.offsetTop - navHeight;
// scroll to height
window.scrollTo({
left: 0,
top: scrollPosition
})
})
})
//footer contact us
const form = document.getElementById('form');
const Einfo=document.getElementById('Einfo');
if(localStorage.getItem('count')==null)
localStorage.setItem('count',0);
form.addEventListener('submit',(e)=>{
Einfo.style.color="red"
Einfo.innerText="please wait message sending"
e.preventDefault();
var count=localStorage.getItem('count');
if(count=='4'){
alert("please wait 5m you already send 3 mail")
let m=new Date().getMinutes();
let time= localStorage.getItem('time')
if( 5+m==time){
count=0;
localStorage.setItem('count',count);
localStorage.setItem('time',m);
}
Einfo.innerText=" "
}
else{
emailjs.sendForm('service_0ou379h', 'template_zzjya8j', form)
.then((result) => {
Einfo.innerText=" "
alert("your message send successfully")
count++;
let m=new Date().getMinutes();
localStorage.setItem('count',count);
localStorage.setItem('time',m);
},(error) => {
Einfo.innerText="error please try few minute later"
console.log(error);
});
form.reset();
}
});
// 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}%)`;
};
window.onscroll = calcScrollValue;
window.onload = calcScrollValue;