-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
48 lines (41 loc) · 1.44 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
// Smooth Scroll
const navLinks = document.querySelectorAll('nav ul li a');
navLinks.forEach(link => {
link.addEventListener('click', (event) => {
event.preventDefault();
document.querySelector(link.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Back to Top Button
const backToTopButton = document.getElementById("back-to-top");
window.onscroll = function() {
scrollFunction();
};
function scrollFunction() {
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) {
backToTopButton.style.display = "block";
} else {
backToTopButton.style.display = "none";
}
}
backToTopButton.addEventListener('click', () => {
window.scrollTo({top: 0, behavior: 'smooth'});
});
// Dark Mode Toggle
const darkModeToggle = document.getElementById('dark-mode-toggle');
darkModeToggle.addEventListener('click', () => {
document.body.classList.toggle('dark-mode');
document.querySelector('header').classList.toggle('dark-mode');
document.querySelector('nav').classList.toggle('dark-mode');
document.querySelectorAll('.contact-links a').forEach(link => {
link.classList.toggle('dark-mode');
});
// Change icon on toggle
if (darkModeToggle.innerHTML.includes('moon')) {
darkModeToggle.innerHTML = '<i class="fas fa-sun"></i>';
} else {
darkModeToggle.innerHTML = '<i class="fas fa-moon"></i>';
}
});