-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
71 lines (58 loc) · 1.95 KB
/
app.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
//from incrementing project
//Section 2 incrementing counters
const counters = document.querySelectorAll('.counter');
counters.forEach((counter) => {
counter.innerText = '0';
const updateCounter = () => {
const target = +counter.getAttribute('data-target');
const c = +counter.innerText;
const increment = target / 250;
if (c < target) {
counter.innerText = `${Math.ceil(c + increment)}`;
setTimeout(updateCounter, 1);
} else {
counter.innerText = target;
}
};
updateCounter();
});
//Typing effect
const title = document.querySelector('.title');
const btnJoin = document.querySelector('.btn-join');
let i = 0;
let txt = title.innerText;
title.innerText = ' ';
let speed = 100;
function typeWriter() {
if (i < txt.length) {
title.innerHTML += txt.charAt(i);
i++;
setTimeout(typeWriter, speed);
}
}
typeWriter(title);
//Show the button at the top of the page after h1 typing effect is finished
setTimeout(() => btnJoin.classList.remove('btn-hidden'), 5000);
//Toggle humburger menu button on smaller screens
const toggleButton = document.querySelector('.toggle-button');
const navLinks = document.querySelector('.nav-links');
toggleButton.addEventListener('click', () => {
navLinks.classList.toggle('active');
});
//Slide effect
//Smooth scrolling when clicking navbar items
document.querySelector('.nav-links').addEventListener('click', function (e) {
// console.log(e.target);
e.preventDefault();
if (e.target.classList.contains('nav-link')) {
const id = e.target.getAttribute('href');
// console.log(id);
navLinks.classList.toggle('active');
document.querySelector(id).scrollIntoView({ behavior: 'smooth' });
}
});
//Smooth scroll 'Join Our Discord' button
const section3 = document.querySelector('#section--3');
btnJoin.addEventListener('click', function (e) {
section3.scrollIntoView({ behavior: 'smooth' });
});