/
varsl
/
HTML-CSS
Обзор
Документация
Войти
/
varsl
/
HTML-CSS
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
frontend/js/main.js
139 строк
5 KB
varsl
Добавление JavaScript логики
21 дек 2025, 23:15
21 дек 2025, 23:15
f803033
Код
Авторство
О чём код?
document.addEventListener('DOMContentLoaded', function() { const menuToggle = document.getElementById('menuToggle'); const navMenu = document.getElementById('navMenu'); if (menuToggle && navMenu) { menuToggle.addEventListener('click', function() { navMenu.classList.toggle('active'); menuToggle.innerHTML = navMenu.classList.contains('active') ? '<i class="fas fa-times"></i>' : '<i class="fas fa-bars"></i>'; }); document.addEventListener('click', function(event) { if (!navMenu.contains(event.target) && !menuToggle.contains(event.target)) { navMenu.classList.remove('active'); menuToggle.innerHTML = '<i class="fas fa-bars"></i>'; } }); } const playSoundButtons = document.querySelectorAll('.play-sound'); playSoundButtons.forEach(button => { button.addEventListener('click', function() { const soundName = this.getAttribute('data-sound'); playAnimalSound(soundName); }); }); function playAnimalSound(soundName) { const audio = new Audio(`assets/sounds/${soundName}.mp3`); audio.play().catch(e => { console.log('Ошибка воспроизведения звука:', e); }); } 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('animate-fade-in'); observer.unobserve(entry.target); } }); }, observerOptions); document.querySelectorAll('.feature-card, .slide, .video-container').forEach(el => { observer.observe(el); }); window.addEventListener('scroll', function() { const header = document.querySelector('.header'); if (window.scrollY > 100) { header.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.1)'; } else { header.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.1)'; } }); const scrollToTopBtn = document.getElementById('scrollToTop'); if (scrollToTopBtn) { window.addEventListener('scroll', function() { if (window.scrollY > 500) { scrollToTopBtn.classList.add('visible'); } else { scrollToTopBtn.classList.remove('visible'); } }); scrollToTopBtn.addEventListener('click', function() { window.scrollTo({ top: 0, behavior: 'smooth' }); }); } const currentYear = document.getElementById('currentYear'); if (currentYear) { currentYear.textContent = new Date().getFullYear(); } const tooltips = document.querySelectorAll('[data-tooltip]'); tooltips.forEach(tooltip => { tooltip.addEventListener('mouseenter', function() { const text = this.getAttribute('data-tooltip'); const tooltipEl = document.createElement('div'); tooltipEl.className = 'custom-tooltip'; tooltipEl.textContent = text; document.body.appendChild(tooltipEl); const rect = this.getBoundingClientRect(); tooltipEl.style.top = (rect.top - tooltipEl.offsetHeight - 10) + 'px'; tooltipEl.style.left = (rect.left + rect.width / 2 - tooltipEl.offsetWidth / 2) + 'px'; }); tooltip.addEventListener('mouseleave', function() { const tooltipEl = document.querySelector('.custom-tooltip'); if (tooltipEl) { tooltipEl.remove(); } }); }); const themeToggle = document.getElementById('themeToggle'); if (themeToggle) { themeToggle.addEventListener('click', function() { document.body.classList.toggle('dark-theme'); const isDark = document.body.classList.contains('dark-theme'); localStorage.setItem('theme', isDark ? 'dark' : 'light'); this.innerHTML = isDark ? '<i class="fas fa-sun"></i>' : '<i class="fas fa-moon"></i>'; }); const savedTheme = localStorage.getItem('theme'); if (savedTheme === 'dark') { document.body.classList.add('dark-theme'); if (themeToggle) { themeToggle.innerHTML = '<i class="fas fa-sun"></i>'; } } } const loadingOverlay = document.getElementById('loadingOverlay'); if (loadingOverlay) { window.addEventListener('load', function() { setTimeout(() => { loadingOverlay.style.opacity = '0'; setTimeout(() => { loadingOverlay.style.display = 'none'; }, 500); }, 1000); }); } });