HTMLify
script.js
Views: 22 | Author: karbonsites
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 | // JavaScript for basic interactivity and animation triggering document.addEventListener('DOMContentLoaded', () => { // 1. Simple Search Bar Toggle (Placeholder functionality) const searchToggle = document.querySelector('.search-toggle'); if (searchToggle) { searchToggle.addEventListener('click', () => { const searchInput = document.querySelector('.search-bar input[type="text"]'); if (searchInput) { searchInput.focus(); } // In a real app, this might toggle a full-screen search overlay }); } // 2. Intersection Observer for Scroll Animations (Applies to all pages) const observerOptions = { root: null, rootMargin: '0px', threshold: 0.1 }; const observer = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.style.opacity = 1; entry.target.style.transform = 'translateY(0) translateX(0)'; entry.target.classList.add('is-visible'); observer.unobserve(entry.target); } }); }, observerOptions); // Find all elements marked for animation but haven't been initialized by HTML classes yet document.querySelectorAll('.fade-in-up, .fade-in-left, .fade-in').forEach(el => { // If the element is already in the viewport on load, it will be handled by the CSS keyframes immediately. // If it's off-screen, observe it. observer.observe(el); }); // Manually set initial state for JS-controlled animation elements if needed, // though in this setup, the CSS handles the initial hidden state via the class being present. document.querySelectorAll('.fade-in-up, .fade-in-left').forEach(el => { if (!el.classList.contains('is-visible')) { el.style.opacity = 0; } }); }); |