-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathscript.js
148 lines (123 loc) · 4.46 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
const btn = document.getElementById("menu-btn");
const overlay = document.getElementById("overlay");
const menu = document.getElementById("mobile-menu");
const counters = document.querySelectorAll(".counter");
const menuBtn = document.getElementById("menu");
const menuContent = document.querySelector(".menu-content");
let scrollStarted = false;
// btn.addEventListener('click', navToggle);
document.addEventListener("scroll", scrollPage);
function navToggle() {
btn.classList.toggle("open");
overlay.classList.toggle("overlay-show");
document.body.classList.toggle("stop-scrolling");
menu.classList.toggle("show-menu");
}
function scrollPage() {
const scrollPos = window.scrollY;
if (scrollPos > 100 && !scrollStarted) {
countUp();
scrollStarted = true;
} else if (scrollPos < 100 && scrollStarted) {
reset();
scrollStarted = false;
}
}
function countUp() {
// counters.forEach((counter) => {
// counter.innerText = '0';
// const updateCounter = () => {
// // Get count target
// const target = counter.getAttribute('data-target');
// // Get current counter value
// const c = +counter.innerText;
// // Create an increment
// const increment = target / 100;
// // If counter is less than target, add increment
// if (c < target) {
// // Round up and set counter value
// counter.innerText = Math.ceil(c + increment);
// // setTimeout(updateCounter, 75);
// } else {
// counter.innerText = target;
// }
// };
// updateCounter();
// });
let animationDuration = 1000;
counters.forEach((counter) => {
const target = parseFloat(counter.getAttribute("data-target"));
const numberOfSteps = Math.floor(animationDuration / 10); // Assuming 10 ms interval
const increment = target / numberOfSteps;
let incCounterValue = 0;
let animation = setInterval(() => {
if (incCounterValue < target) {
incCounterValue += increment;
counter.innerText = Math.round(incCounterValue);
} else {
clearInterval(animation);
}
}, 10);
});
}
function reset() {
counters.forEach((counter) => (counter.innerHTML = "0"));
}
// menu button
function myFunction(x) {
x.classList.toggle("change");
}
menuBtn.addEventListener("click", () => {
menuContent.classList.toggle("active");
});
// Function to show the toast notification
function showSubscribeToast() {
var toast = document.getElementById("subscribe-toast");
toast.style.display = "block";
setTimeout(function () {
toast.style.display = "none";
}, 5000); // Hide the toast after 5 seconds
}
// Function to handle the "Subscribe" button click
function subscribeToNewsletter() {
// You can add your newsletter subscription logic here
// For demonstration purposes, we'll simply show the toast
showSubscribeToast();
}
// Add an event listener to the "Subscribe" button
document.getElementById("subscribe-button").addEventListener("click", subscribeToNewsletter);
// Show the toast notification when the page loads (for demonstration)
window.addEventListener("load", showSubscribeToast);
// Function to handle form submission
document.getElementById("newsletter-form").addEventListener("submit", function (event) {
event.preventDefault(); // Prevent the form from submitting
// You can add your form submission logic here
// For demonstration purposes, show a success message
document.getElementById("newsletter-form").innerHTML =
'<p>Thank you for subscribing!</p>';
});
// Added Event Listener on satellite option for screen size smaller than 750px
let satelliteOption=document.querySelector("#secondary");
satelliteOption.addEventListener(("click"),()=>{
document.querySelector(".material-symbols-outlined").classList.toggle("rotate-Arrow")
let satellites=document.querySelectorAll(".satellite-option");
satellites.forEach((ele)=>{
ele.classList.toggle("display-satellites");
})
})
document.addEventListener("DOMContentLoaded", function() {
const scrollToTopButton = document.getElementById("scrollToTopButton");
window.onscroll = function() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
scrollToTopButton.style.display = "block";
} else {
scrollToTopButton.style.display = "none";
}
};
scrollToTopButton.addEventListener("click", function() {
window.scrollTo({
top: 0,
behavior: "smooth"
});
});
});