Skip to content

Commit

Permalink
Update main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
macedonianluke committed Oct 25, 2024
1 parent 485bbfb commit 1b47ca6
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions js/v2/main.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
document.addEventListener('DOMContentLoaded', () => {
const cursor = document.querySelector('.cursor');
const menu = document.querySelector('.menu');
// Menu functionality
const menuButton = document.querySelector('.menu-toggle');
const menu = document.querySelector('.menu');

// Convert "Menu" text to a button if it doesn't exist
if (!menuButton) {
const menuText = document.querySelector('div:contains("Menu")');
if (menuText) {
const button = document.createElement('button');
button.className = 'menu-toggle';
button.textContent = 'Menu';
menuText.replaceWith(button);
}
}

// Add menu toggle functionality
document.querySelector('.menu-toggle')?.addEventListener('click', () => {
menu?.classList.toggle('active');
});
if (menuButton && menu) {
menuButton.addEventListener('click', () => {
menu.classList.toggle('active');
// Optional: Toggle button text
menuButton.textContent = menu.classList.contains('active') ? 'Close' : 'Menu';
});

// Close menu when clicking menu links
const menuLinks = document.querySelectorAll('.menu-nav a');
menuLinks.forEach(link => {
link.addEventListener('click', () => {
menu?.classList.remove('active');
// Close menu when clicking menu links
const menuLinks = document.querySelectorAll('.menu-nav a');
menuLinks.forEach(link => {
link.addEventListener('click', () => {
menu.classList.remove('active');
menuButton.textContent = 'Menu';
});
});
});

// Existing cursor code
// Add escape key functionality to close menu
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && menu.classList.contains('active')) {
menu.classList.remove('active');
menuButton.textContent = 'Menu';
}
});
}

// Cursor functionality
const cursor = document.querySelector('.cursor');

if (!cursor) {
console.error('Cursor element not found');
return;
Expand Down

0 comments on commit 1b47ca6

Please sign in to comment.