-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
41 lines (33 loc) · 970 Bytes
/
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
const scrollTp = document.querySelector('#scrollToTop');
scrollTp.addEventListener('click', function () {
window.scrollTo({
top: 0,
left: 0,
behavior: "smooth"
})
})
window.addEventListener('scroll', function () {
if (window.scrollY >= 700) {
scrollTp.style.opacity = 1
} else {
scrollTp.style.opacity = 0
}
})
// Dark Mode
const themeToggle = document.querySelector('.checkbox');
const body = document.querySelector('body');
const darkmode = localStorage.getItem('dark');
themeToggle.addEventListener('change', function () {
body.classList.toggle('dark')
if (body.classList.contains('dark')) {
localStorage.setItem('dark', 'active')
} else {
localStorage.removeItem('dark')
}
})
// Navbar
const menu = document.querySelector('.fa-bars')
const navbar = document.querySelector('.navbar ul')
menu.addEventListener('click', () => {
navbar.classList.toggle('active')
})