mirror of
https://github.com/YouHaveTrouble/youhavetrouble.github.io.git
synced 2026-05-12 06:16:55 +00:00
actually commit this because it's been laying here for literal months
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
const navLinks = {
|
||||
hero: document.querySelector('a[href="#hero"]'),
|
||||
projects: document.querySelector('a[href="#projects"]'),
|
||||
}
|
||||
|
||||
const sections = {
|
||||
hero: document.querySelector('#hero'),
|
||||
projects: document.querySelector('#projects'),
|
||||
}
|
||||
|
||||
changeSection(window.location.hash ? window.location.hash : '#hero')
|
||||
|
||||
for (const link of Object.values(navLinks)) {
|
||||
link.addEventListener('click', (e) => {
|
||||
const target = e.target.getAttribute('href');
|
||||
if (!target.startsWith('#')) return;
|
||||
changeSection(target)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function changeSection(sectionName) {
|
||||
for (const link of Object.values(navLinks)) {
|
||||
link.classList.remove('active');
|
||||
}
|
||||
for (const link of Object.values(sections)) {
|
||||
link.classList.remove('active');
|
||||
}
|
||||
|
||||
if (!sectionName.startsWith('#')) {
|
||||
sectionName = '#' + sectionName;
|
||||
}
|
||||
|
||||
const targetElement = document.querySelector(sectionName);
|
||||
if (!targetElement) return;
|
||||
targetElement.classList.add('active');
|
||||
navLinks[targetElement.id].classList.add('active');
|
||||
}
|
||||
|
||||
/** Shuffle data-info elements */
|
||||
function shuffleArray(array) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
}
|
||||
|
||||
const dataInfo = document.querySelector("[data-info]");
|
||||
const dataInfoElements = [];
|
||||
for (const element of dataInfo.children) {
|
||||
dataInfoElements.push(element);
|
||||
}
|
||||
shuffleArray(dataInfoElements);
|
||||
dataInfo.innerHTML = "";
|
||||
for (const element of dataInfoElements) {
|
||||
dataInfo.appendChild(element);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user