Spaces:
Running
Running
File size: 4,494 Bytes
8cb0174 407fc31 8cb0174 407fc31 8cb0174 407fc31 8cb0174 407fc31 8cb0174 407fc31 8cb0174 407fc31 8cb0174 407fc31 8cb0174 407fc31 8cb0174 | 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 |
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
// Close mobile menu if open
const header = document.querySelector('custom-header');
if (header) {
const shadowRoot = header.shadowRoot;
const navMenu = shadowRoot.getElementById('navMenu');
const menuBtn = shadowRoot.getElementById('menuBtn');
if (navMenu.classList.contains('active')) {
navMenu.classList.remove('active');
const menuIcon = menuBtn.querySelector('i');
menuIcon.setAttribute('data-feather', 'menu');
feather.replace();
}
}
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Form submission handling with better UX
const contactForm = document.querySelector('#contact form');
if (contactForm) {
contactForm.addEventListener('submit', async function(e) {
e.preventDefault();
const submitBtn = this.querySelector('button[type="submit"]');
const originalBtnText = submitBtn.innerHTML;
try {
// Show loading state
submitBtn.innerHTML = `
<span class="inline-flex items-center">
<svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
Отправка...
</span>
`;
submitBtn.disabled = true;
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 1500));
// Show success
const toast = document.createElement('div');
toast.className = 'fixed top-6 right-6 bg-green-500 text-white px-6 py-3 rounded-lg shadow-lg flex items-center animate-fade-in-up z-50';
toast.innerHTML = `
<i data-feather="check-circle" class="w-5 h-5 mr-2"></i>
<span>Сообщение отправлено! Мы свяжемся с вами в ближайшее время.</span>
`;
document.body.appendChild(toast);
feather.replace();
// Remove toast after 5s
setTimeout(() => {
toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
setTimeout(() => toast.remove(), 300);
}, 5000);
// Reset form
this.reset();
} catch (error) {
console.error('Form submission error:', error);
} finally {
submitBtn.innerHTML = originalBtnText;
submitBtn.disabled = false;
}
});
}
// Enhanced animation on scroll
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-fade-in-up');
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('[class*="animate-"]').forEach(el => {
observer.observe(el);
});
// Initialize tooltips
document.querySelectorAll('[data-tooltip]').forEach(el => {
const tooltip = document.createElement('div');
tooltip.className = 'absolute hidden bg-gray-900 text-white text-xs rounded py-1 px-2 whitespace-nowrap z-50';
tooltip.textContent = el.getAttribute('data-tooltip');
document.body.appendChild(tooltip);
el.addEventListener('mouseenter', () => {
const rect = el.getBoundingClientRect();
tooltip.style.top = `${rect.top - 30}px`;
tooltip.style.left = `${rect.left + rect.width/2 - tooltip.offsetWidth/2}px`;
tooltip.classList.remove('hidden');
});
el.addEventListener('mouseleave', () => {
tooltip.classList.add('hidden');
});
});
|