f88fa's picture
هل تشاهد هذا الموقع "https://file.f88fa.com/drahmed/"
312479e verified
Raw History Blame Contribute Delete
8.63 kB
// Theme Toggle Functionality
document.addEventListener('DOMContentLoaded', () => {
// Check for saved theme preference or default to dark
const html = document.documentElement;
const savedTheme = localStorage.getItem('theme') || 'dark';
if (savedTheme === 'dark') {
html.classList.add('dark');
} else {
html.classList.remove('dark');
}
// Mobile Menu Toggle
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const mobileMenu = document.getElementById('mobile-menu');
const mobileMenuClose = document.getElementById('mobile-menu-close');
if (mobileMenuBtn && mobileMenu) {
mobileMenuBtn.addEventListener('click', () => {
mobileMenu.classList.remove('translate-x-full');
document.body.style.overflow = 'hidden';
});
if (mobileMenuClose) {
mobileMenuClose.addEventListener('click', () => {
mobileMenu.classList.add('translate-x-full');
document.body.style.overflow = '';
});
}
// Close menu when clicking on links
mobileMenu.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.add('translate-x-full');
document.body.style.overflow = '';
});
});
}
// Smooth Scroll 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) {
const offsetTop = target.offsetTop - 80; // Account for fixed header
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
// Intersection Observer for Reveal Animations
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('active');
observer.unobserve(entry.target); // Only animate once
}
});
}, observerOptions);
// Observe all elements with reveal class
document.querySelectorAll('.reveal').forEach(el => {
observer.observe(el);
});
// Parallax Effect for Hero Section
const heroSection = document.querySelector('section:first-of-type');
if (heroSection) {
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const parallaxElements = heroSection.querySelectorAll('.absolute');
parallaxElements.forEach((el, index) => {
const speed = 0.5 + (index * 0.1);
el.style.transform = `translateY(${scrolled * speed}px)`;
});
});
}
// Navbar Background on Scroll
const navbar = document.querySelector('nav');
if (navbar) {
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('shadow-lg', 'bg-white/90', 'dark:bg-slate-900/90', 'backdrop-blur-md');
navbar.classList.remove('bg-transparent');
} else {
navbar.classList.remove('shadow-lg', 'bg-white/90', 'dark:bg-slate-900/90', 'backdrop-blur-md');
navbar.classList.add('bg-transparent');
}
});
}
// Counter Animation for Stats
const animateCounter = (element, target, duration = 2000) => {
let start = 0;
const increment = target / (duration / 16);
const updateCounter = () => {
start += increment;
if (start < target) {
element.textContent = Math.ceil(start) + '+';
requestAnimationFrame(updateCounter);
} else {
element.textContent = target + '+';
}
};
updateCounter();
};
// Observe stats for counter animation
const statsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const statNumber = entry.target.querySelector('.text-3xl');
if (statNumber && !statNumber.classList.contains('counted')) {
const target = parseInt(statNumber.textContent);
statNumber.classList.add('counted');
animateCounter(statNumber, target);
}
}
});
}, { threshold: 0.5 });
document.querySelectorAll('.grid > div').forEach(stat => {
if (stat.querySelector('.text-3xl')) {
statsObserver.observe(stat);
}
});
// Form Validation (if forms exist)
const forms = document.querySelectorAll('form');
forms.forEach(form => {
form.addEventListener('submit', (e) => {
e.preventDefault();
// Basic validation
let isValid = true;
const requiredFields = form.querySelectorAll('[required]');
requiredFields.forEach(field => {
if (!field.value.trim()) {
isValid = false;
field.classList.add('border-red-500');
// Remove error after 3 seconds
setTimeout(() => {
field.classList.remove('border-red-500');
}, 3000);
}
});
if (isValid) {
// Show success message
const btn = form.querySelector('button[type="submit"]');
const originalText = btn.innerHTML;
btn.innerHTML = '<i data-feather="check" class="w-5 h-5 inline mr-2"></i> Sent Successfully!';
btn.disabled = true;
feather.replace();
setTimeout(() => {
btn.innerHTML = originalText;
btn.disabled = false;
form.reset();
feather.replace();
}, 3000);
}
});
});
// Dynamic Year in Footer
const yearSpan = document.querySelector('.current-year');
if (yearSpan) {
yearSpan.textContent = new Date().getFullYear();
}
// Tilt Effect for Cards (3D hover)
const cards = document.querySelectorAll('.hover-3d');
cards.forEach(card => {
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const rotateX = (y - centerY) / 20;
const rotateY = (centerX - x) / 20;
card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale3d(1.05, 1.05, 1.05)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'perspective(1000px) rotateX(0) rotateY(0) scale3d(1, 1, 1)';
});
});
// Lazy Loading Images
const lazyImages = document.querySelectorAll('img[data-src]');
const imageObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.removeAttribute('data-src');
imageObserver.unobserve(img);
}
});
});
lazyImages.forEach(img => imageObserver.observe(img));
console.log('🎨 Indigo Horizon Studio - Ready to create magic!');
});
// Theme Toggle Function (Global)
function toggleTheme() {
const html = document.documentElement;
const isDark = html.classList.contains('dark');
if (isDark) {
html.classList.remove('dark');
localStorage.setItem('theme', 'light');
} else {
html.classList.add('dark');
localStorage.setItem('theme', 'dark');
}
// Dispatch custom event for components
window.dispatchEvent(new CustomEvent('themechange', {
detail: { theme: isDark ? 'light' : 'dark' }
}));
}
// Export for Web Components
window.toggleTheme = toggleTheme;