-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathapp.js
More file actions
125 lines (104 loc) · 3.15 KB
/
app.js
File metadata and controls
125 lines (104 loc) · 3.15 KB
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
$(document).ready(function(){
$(window).scroll(function(){
// scroll-up button show/hide script
if(this.scrollY > 500){
$('.scroll-up-btn').addClass("show");
}else{
$('.scroll-up-btn').removeClass("show");
}
});
// slide-up script
$('.scroll-up-btn').click(function(){
$('html').animate({scrollTop: 0});
// removing smooth scroll on slide-up button click
// $('html').css("scrollBehavior", "auto");
});
});
// Numbers
let valueDisplays = document.querySelectorAll(".num");
let interval = 4000;
valueDisplays.forEach((valueDisplay) => {
let startValue = 0;
let endValue = parseInt(valueDisplay.getAttribute("data-val"));
let duration = Math.floor(interval / endValue);
let counter = setInterval(function () {
startValue +=1;
valueDisplay.textContent = startValue;
if (startValue == endValue) {
clearInterval(counter);
}
}, duration);
});
// end
let slides = document.querySelectorAll('.slide');
for (let slide of slides) {
slide.addEventListener('click', () => {
clearActiveClasses();
slide.classList.add('active');
})
}
function clearActiveClasses() {
slides.forEach((slide) => {
slide.classList.remove('active');
})
}
/* FAQ section */
let faqItems = document.querySelectorAll('.faq-item');
faqItems.forEach((item) => {
item.addEventListener('click', () => {
// Find the button element inside the FAQ item and trigger a click
const button = item.querySelector('button');
if (button) {
button.click();
}
});
});
/* Counterup feature for Number Speaks Louder section */
$('.counter-count').each(function () {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 4000,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
}
});
});
function isInViewport(element) {
const rect = element.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
function addCommas(number) {
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
function updateCounters() {
if (!animationStarted && isInViewport(counters[0])) {
counters.forEach((counter) => {
counter.innerText = '0';
const targetWithCommas = counter.getAttribute('data-target');
const target = parseFloat(targetWithCommas.replace(/,/g, ''));
const increment = target / 400;
function updateCounter(current) {
if (current < target) {
const newValue = Math.ceil(current + increment);
counter.innerText = addCommas(newValue) + "+";
setTimeout(() => updateCounter(newValue), 1);
} else {
counter.innerText = addCommas(target) + "+";
}
}
updateCounter(0);
animationStarted = true;
});
}
}
const counters = document.querySelectorAll('.count');
let animationStarted = false;
window.addEventListener('scroll', updateCounters);
updateCounters();