-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
154 lines (132 loc) · 4.38 KB
/
script.js
File metadata and controls
154 lines (132 loc) · 4.38 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const navbar = document.querySelector('.navbar');
const navMenu = document.querySelector('.nav-menu');
const hamburger = document.getElementById('hamburger');
const themeToggle = document.getElementById('themeToggle');
const backToTop = document.getElementById('backToTop');
const navLinks = document.querySelectorAll('.nav-link');
const typingText = document.getElementById('typingText');
const skillBars = document.querySelectorAll('.skill-progress');
const phrases = [
'Junior Developer',
'Java Developer',
'Web Developer',
'Öyrənməyə həvəsli!'
];
let phraseIndex = 0;
let charIndex = 0;
let isDeleting = false;
let typingSpeed = 100;
function typeEffect() {
const currentPhrase = phrases[phraseIndex];
if (isDeleting) {
typingText.textContent = currentPhrase.substring(0, charIndex - 1);
charIndex--;
typingSpeed = 50;
} else {
typingText.textContent = currentPhrase.substring(0, charIndex + 1);
charIndex++;
typingSpeed = 100;
}
if (!isDeleting && charIndex === currentPhrase.length) {
typingSpeed = 2000;
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
phraseIndex = (phraseIndex + 1) % phrases.length;
typingSpeed = 500;
}
setTimeout(typeEffect, typingSpeed);
}
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
hamburger.classList.remove('active');
navMenu.classList.remove('active');
const targetId = link.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
const offsetTop = targetSection.offsetTop - 70;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
function updateActiveNavLink() {
const sections = document.querySelectorAll('section[id]');
const scrollPos = window.scrollY + 100;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollPos >= sectionTop && scrollPos < sectionTop + sectionHeight) {
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + sectionId) {
link.classList.add('active');
}
});
}
});
}
function toggleTheme() {
document.body.classList.toggle('dark-mode');
const icon = themeToggle.querySelector('i');
if (document.body.classList.contains('dark-mode')) {
icon.classList.remove('fa-moon');
icon.classList.add('fa-sun');
localStorage.setItem('theme', 'dark');
} else {
icon.classList.remove('fa-sun');
icon.classList.add('fa-moon');
localStorage.setItem('theme', 'light');
}
}
function loadTheme() {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark-mode');
themeToggle.querySelector('i').classList.remove('fa-moon');
themeToggle.querySelector('i').classList.add('fa-sun');
}
}
themeToggle.addEventListener('click', toggleTheme);
loadTheme();
function toggleBackToTop() {
if (window.scrollY > 500) {
backToTop.classList.add('visible');
} else {
backToTop.classList.remove('visible');
}
}
backToTop.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
function animateSkillBars() {
skillBars.forEach(bar => {
const progress = bar.getAttribute('data-progress');
bar.style.width = progress + '%';
});
}
function handleNavbarScroll() {
if (window.scrollY > 50) {
navbar.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.boxShadow = '0 1px 2px rgba(0, 0, 0, 0.05)';
}
}
window.addEventListener('scroll', () => {
updateActiveNavLink();
toggleBackToTop();
handleNavbarScroll();
});
document.addEventListener('DOMContentLoaded', () => {
typeEffect();
updateActiveNavLink();
setTimeout(animateSkillBars, 500);
});