-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
170 lines (143 loc) · 5.67 KB
/
index.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
function opennavbar() {
const navbar = document.getElementById('navbar');
navbar.style.height = '100%';
}
function closenavbar() {
const navbar = document.getElementById('navbar');
navbar.style.height = '0%';
}
document.addEventListener('DOMContentLoaded', () => {
const content = "Hello there ,\n am manases a front-end developer from kenya ";
let index = 0;
const typingSpeed = 100; // Adjust typing speed in milliseconds
const interval = setInterval(() => {
document.getElementById('intro-text').textContent += content[index];
index++;
if (index === content.length) {
clearInterval(interval);
}
}, typingSpeed);
// Initialize the "about me" section
openaboutme();
// Add event listeners for the accordion functionality
const scontElements = document.querySelectorAll('.scont');
scontElements.forEach(scont => {
scont.addEventListener('click', () => {
const content = scont.nextElementSibling;
if (content.style.display === 'block') {
content.style.display = 'none';
} else {
content.style.display = 'block';
}
});
});
// Add event listeners for navbar buttons
document.getElementById('navbtn-home').addEventListener('click', () => {
document.getElementById('home').scrollIntoView({ behavior: 'smooth' });
});
document.getElementById('navbtn-about').addEventListener('click', () => {
document.getElementById('about').scrollIntoView({ behavior: 'smooth' });
});
document.getElementById('navbtn-projects').addEventListener('click', () => {
document.getElementById('projects').scrollIntoView({ behavior: 'smooth' });
});
document.getElementById('navbtn-contact').addEventListener('click', () => {
document.getElementById('contact').scrollIntoView({ behavior: 'smooth' });
});
// Initialize theme toggling functionality
const toggleButton = document.getElementById('theme-toggle');
toggleButton.addEventListener('click', changetheme);
// Back to top button functionality
const backToTopButton = document.createElement('button');
backToTopButton.classList.add('back-to-top');
backToTopButton.innerHTML = `
<svg class="progress-circle" width="50" height="50" viewBox="0 0 36 36">
<circle class="progress-bg" cx="18" cy="18" r="15.915" fill="none" stroke="#e6e6e6" stroke-width="4"/>
<circle class="progress" cx="18" cy="18" r="15.915" fill="none" stroke="rgb(248, 0, 0)" stroke-width="4" stroke-dasharray="100" stroke-dashoffset="100"/>
</svg>
<i class="fa fa-arrow-up"></i>
`;
document.body.appendChild(backToTopButton);
backToTopButton.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
window.addEventListener('scroll', () => {
const scrollTop = window.scrollY;
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
const progress = (scrollTop / docHeight) * 100;
setProgress(progress);
if (scrollTop > 100) {
backToTopButton.classList.add('show');
} else {
backToTopButton.classList.remove('show');
}
});
});
function openaboutme() {
activateSection('about-me');
moveStatusBar(document.getElementById('about-me-btn'));
}
function openeducation() {
activateSection('education');
moveStatusBar(document.getElementById('edu-btn'));
}
function openskills() {
activateSection('skills');
moveStatusBar(document.getElementById('skill-btn'));
}
function activateSection(sectionId) {
const sections = document.querySelectorAll('.aboutme');
sections.forEach(section => section.classList.remove('active'));
document.getElementById(sectionId).classList.add('active');
}
function moveStatusBar(activeButton) {
const bar = document.getElementById('bar');
bar.style.width = `${activeButton.offsetWidth}px`;
bar.style.marginLeft = `${activeButton.offsetLeft}px`;
}
// Function to flip project cards
function flip(card) {
card.classList.toggle('flip');
}
// Function to toggle accordion
function toggleAccordion(title) {
title.classList.toggle('active');
const mainCon = title.nextElementSibling;
if (mainCon.style.display === 'block') {
mainCon.style.display = 'none';
} else {
mainCon.style.display = 'block';
}
}
// JavaScript to handle theme toggling
function changetheme() {
const body = document.body;
const toggleButton = document.getElementById('theme-toggle');
if (body.classList.contains('light')) {
body.classList.replace('light', 'dark');
toggleButton.classList.replace('fa-sun', 'fa-moon');
} else {
body.classList.replace('dark', 'light');
toggleButton.classList.replace('fa-moon', 'fa-sun');
}
}
// JavaScript to handle theme toggling 2
function theme() {
const body = document.body;
const toggleButton = document.getElementById('theme');
if (body.classList.contains('light')) {
body.classList.replace('light', 'dark');
toggleButton.classList.replace('fa-sun', 'fa-moon');
} else {
body.classList.replace('dark', 'light');
toggleButton.classList.replace('fa-moon', 'fa-sun');
}
}
function setProgress(percent) {
const circle = document.querySelector('.progress');
const radius = circle.r.baseVal.value;
const circumference = 2 * Math.PI * radius;
circle.style.strokeDasharray = `${circumference} ${circumference}`;
const offset = circumference - (percent / 100) * circumference;
circle.style.strokeDashoffset = offset;
}