-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
124 lines (105 loc) · 3.89 KB
/
script.js
File metadata and controls
124 lines (105 loc) · 3.89 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function updateThemeIcons(isDark) {
const lightIcons = document.querySelectorAll('#theme-toggle-light-icon, #theme-toggle-light-icon-mobile');
const darkIcons = document.querySelectorAll('#theme-toggle-dark-icon, #theme-toggle-dark-icon-mobile');
if (isDark) {
lightIcons.forEach(icon => icon.classList.remove('hidden'));
darkIcons.forEach(icon => icon.classList.add('hidden'));
} else {
lightIcons.forEach(icon => icon.classList.add('hidden'));
darkIcons.forEach(icon => icon.classList.remove('hidden'));
}
}
function initTheme() {
const isDark = localStorage.theme === 'dark' ||
(!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches);
if (isDark) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
updateThemeIcons(isDark);
}
initTheme();
['theme-toggle', 'theme-toggle-mobile'].forEach(id => {
const toggleBtn = document.getElementById(id);
if (toggleBtn) {
toggleBtn.addEventListener('click', function() {
document.documentElement.classList.toggle('dark');
const isDark = document.documentElement.classList.contains('dark');
localStorage.theme = isDark ? 'dark' : 'light';
updateThemeIcons(isDark);
});
}
});
document.getElementById('menu-toggle').addEventListener('click', function() {
document.getElementById('mobile-menu').classList.toggle('hidden');
});
const scrollToTopBtn = document.getElementById('scrollToTop');
window.addEventListener('scroll', function() {
if (window.pageYOffset > 300) {
scrollToTopBtn.classList.remove('invisible', 'opacity-0', 'translate-y-10');
scrollToTopBtn.classList.add('opacity-100', 'translate-y-0');
} else {
scrollToTopBtn.classList.add('invisible', 'opacity-0', 'translate-y-10');
scrollToTopBtn.classList.remove('opacity-100', 'translate-y-0');
}
});
scrollToTopBtn.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
const typewriter = document.getElementById('typewriter');
const designations = ['Web Developer', 'UI/UX Designer', 'Programmer'];
let designationIndex = 0;
let charIndex = 0;
let isDeleting = false;
let typingSpeed = 100;
function type() {
const currentDesignation = designations[designationIndex];
if (isDeleting) {
typewriter.textContent = currentDesignation.substring(0, charIndex - 1);
charIndex--;
typingSpeed = 50;
} else {
typewriter.textContent = currentDesignation.substring(0, charIndex + 1);
charIndex++;
typingSpeed = 100;
}
if (!isDeleting && charIndex === currentDesignation.length) {
isDeleting = true;
typingSpeed = 1000;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
designationIndex = (designationIndex + 1) % designations.length;
}
setTimeout(type, typingSpeed);
}
type();
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
function createAnimationObserver() {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// Add the appropriate animation class based on data attribute
const animationType = entry.target.dataset.animation;
if (animationType) {
entry.target.classList.add(animationType);
}
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('[data-animation]').forEach((element) => {
element.classList.add('hidden-element');
observer.observe(element);
});
}
document.addEventListener('DOMContentLoaded', () => {
createAnimationObserver();
});