-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
59 lines (50 loc) · 1.39 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
'use strict';
const navbar = document.querySelector('.navbar-scroll');
const links = document.querySelectorAll('.nav-link');
const scrollupBtn = document.querySelector('.btn-back-to-top');
const year = document.querySelector('.actual-year');
const homeLink = document.querySelector('a[href="#home"]');
window.onload = function () {
window.scrollTo(0, 0);
};
window.addEventListener('scroll', function () {
if (window.pageYOffset > 0) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
links.forEach(link => {
link.addEventListener('click', function () {
links.forEach(link => {
link.classList.remove('active');
});
link.classList.add('active');
});
});
// Scroll up
window.onscroll = function scrollFunction() {
if (
document.body.scrollTop > 200 ||
document.documentElement.scrollTop > 200
) {
scrollupBtn.style.display = 'block';
} else {
scrollupBtn.style.display = 'none';
}
};
scrollupBtn.addEventListener('click', backToTop);
function removeActiveClass() {
const activeLink = document.querySelector('.active');
if (activeLink) {
activeLink.classList.remove('active');
}
}
function backToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
removeActiveClass();
homeLink.classList.add('active');
}
// Actual year in copyright
year.textContent = new Date().getFullYear();