forked from swaraj-das/Collect-your-GamingTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
69 lines (57 loc) · 1.95 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var menuList = document.getElementById("menuList");
menuList.style.maxHeight = "0px";
function toggleMenu() {
if (menuList.style.maxHeight == "0px") {
menuList.style.maxHeight = "160px";
} else {
menuList.style.maxHeight = "0px";
}
}
window.onscroll = function() {
updateProgressBar();
};
function updateProgressBar() {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var scrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
var scrollPercent = (scrollTop / scrollHeight) * 100;
document.getElementById("progressBar").style.width = scrollPercent + "%";
}
document.addEventListener('DOMContentLoaded', () => {
console.log("Website loaded successfully!");
});
// Show or hide the scroll-top button based on scroll position
window.addEventListener('scroll', function() {
const scrollTopButton = document.querySelector('.scroll-top');
if (window.pageYOffset > 300) {
scrollTopButton.style.display = 'block';
} else {
scrollTopButton.style.display = 'none';
}
});
// Smooth scroll to top when the button is clicked
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
}
function toggleTheme() {
const body = document.body;
const themeToggle = document.getElementById('theme-toggle');
body.classList.toggle('dark-mode', themeToggle.checked);
// Save the user's preference in localStorage
if (themeToggle.checked) {
localStorage.setItem('theme', 'dark');
} else {
localStorage.setItem('theme', 'light');
}
}
// Load theme from localStorage on page load
window.onload = () => {
const savedTheme = localStorage.getItem('theme');
const themeToggle = document.getElementById('theme-toggle');
if (savedTheme === 'dark') {
document.body.classList.add('dark-mode');
themeToggle.checked = true;
}
};