monolith-elements / script.js
vitalam's picture
Can you redesign with Brand: MONOLITH · 原素
9105f53 verified
Raw History Blame Contribute Delete
2.7 kB
// Mobile menu toggle functionality
document.addEventListener('DOMContentLoaded', function() {
const menuButton = document.querySelector('nav button');
const mobileMenu = document.createElement('div');
mobileMenu.className = 'md:hidden fixed inset-0 bg-[#0D0D0D] z-50 flex flex-col items-center justify-center hidden';
mobileMenu.innerHTML = `
<button class="absolute top-8 right-8 text-white">
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1">
<line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line>
</svg>
</button>
<div class="flex flex-col items-center space-y-12 text-white text-lg">
<a href="#products" class="hover:text-[#FF1069] transition-colors tracking-widest">FRAGRANCES</a>
<a href="#about" class="hover:text-[#FF1069] transition-colors tracking-widest">ABOUT</a>
<a href="#collections" class="hover:text-[#FF1069] transition-colors tracking-widest">COLLECTIONS</a>
<a href="#" class="hover:text-[#FF1069] transition-colors tracking-widest">JOURNAL</a>
</div>
`;
document.body.appendChild(mobileMenu);
menuButton.addEventListener('click', function() {
mobileMenu.classList.remove('hidden');
});
mobileMenu.querySelector('button').addEventListener('click', function() {
mobileMenu.classList.add('hidden');
});
// Close mobile menu when clicking on a link
mobileMenu.querySelectorAll('a').forEach(link => {
link.addEventListener('click', function() {
mobileMenu.classList.add('hidden');
});
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Add subtle scroll animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in');
}
});
}, observerOptions);
document.querySelectorAll('section').forEach(section => {
observer.observe(section);
});
});