-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
52 lines (46 loc) · 1.81 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
// Smooth Scroll Function
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
target.scrollIntoView({
behavior: 'smooth',
block: 'start' // Scroll to the top of the target element
});
});
});
// Responsive Mobile Menu Toggle
function toggleMobileMenu(menuId) {
const menu = document.getElementById(menuId);
menu.classList.toggle('is-active');
}
// Theme Switcher (Light/Dark Mode)
function toggleTheme() {
const body = document.body;
body.classList.toggle('dark-theme');
const theme = body.classList.contains('dark-theme') ? 'dark' : 'light';
localStorage.setItem('theme', theme); // Save the theme preference
}
// Apply the saved theme on page load
document.addEventListener('DOMContentLoaded', () => {
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
document.body.classList.add(savedTheme === 'dark' ? 'dark-theme' : 'light-theme');
}
// Optionally, bind the theme toggle to a specific element
const themeToggleBtn = document.getElementById('theme-toggle');
if (themeToggleBtn) {
themeToggleBtn.addEventListener('click', toggleTheme);
}
});
// Dynamic Button Effects
document.querySelectorAll('.social-link').forEach(button => {
button.addEventListener('mouseenter', () => {
button.style.transform = 'translateY(-2px)';
button.style.boxShadow = '0px 8px 12px rgba(0, 0, 0, 0.2)';
});
button.addEventListener('mouseleave', () => {
button.style.transform = 'translateY(0)';
button.style.boxShadow = '0px 4px 6px rgba(0, 0, 0, 0.1)';
});
});