Spaces:
Running
Running
Download script.js from elenga/rythmes-de-brazza: direct link, hf CLI and curl.
- Browser
- Download file 5.72 kB
-
https://huggingface.co/spaces/elenga/rythmes-de-brazza/resolve/main/script.js
- Command line
-
hf download hf://spaces/elenga/rythmes-de-brazza/script.js
-
curl -L -o script.js https://huggingface.co/spaces/elenga/rythmes-de-brazza/resolve/main/script.js
5.72 kB
| // Carousel functionality | |
| let currentSlide = 0; | |
| const carouselTrack = document.getElementById('carouselTrack'); | |
| const slides = document.querySelectorAll('.carousel-slide'); | |
| const totalSlides = slides.length / 2; // We have duplicate slides for infinite scroll | |
| function updateCarousel() { | |
| const slideWidth = window.innerWidth >= 768 ? 33.333 : 100; | |
| const offset = currentSlide * slideWidth; | |
| carouselTrack.style.transform = `translateX(-${offset}%)`; | |
| } | |
| function nextSlide() { | |
| currentSlide++; | |
| updateCarousel(); | |
| // Reset to beginning when reaching the end | |
| if (currentSlide >= totalSlides) { | |
| setTimeout(() => { | |
| carouselTrack.style.transition = 'none'; | |
| currentSlide = 0; | |
| updateCarousel(); | |
| setTimeout(() => { | |
| carouselTrack.style.transition = 'transform 0.5s ease-in-out'; | |
| }, 50); | |
| }, 500); | |
| } | |
| } | |
| function prevSlide() { | |
| currentSlide--; | |
| updateCarousel(); | |
| // Jump to end when going past beginning | |
| if (currentSlide < 0) { | |
| setTimeout(() => { | |
| carouselTrack.style.transition = 'none'; | |
| currentSlide = totalSlides - 1; | |
| updateCarousel(); | |
| setTimeout(() => { | |
| carouselTrack.style.transition = 'transform 0.5s ease-in-out'; | |
| }, 50); | |
| }, 500); | |
| } | |
| } | |
| // Auto-play carousel | |
| let autoplayInterval = setInterval(nextSlide, 4000); | |
| // Carousel controls | |
| document.getElementById('nextBtn')?.addEventListener('click', () => { | |
| clearInterval(autoplayInterval); | |
| nextSlide(); | |
| autoplayInterval = setInterval(nextSlide, 4000); | |
| }); | |
| document.getElementById('prevBtn')?.addEventListener('click', () => { | |
| clearInterval(autoplayInterval); | |
| prevSlide(); | |
| autoplayInterval = setInterval(nextSlide, 4000); | |
| }); | |
| // Pause autoplay on hover | |
| const carouselContainer = document.querySelector('.carousel-container'); | |
| if (carouselContainer) { | |
| carouselContainer.addEventListener('mouseenter', () => clearInterval(autoplayInterval)); | |
| carouselContainer.addEventListener('mouseleave', () => { | |
| autoplayInterval = setInterval(nextSlide, 4000); | |
| }); | |
| } | |
| // Intersection Observer for 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('animate-fade-in'); | |
| } | |
| }); | |
| }, observerOptions); | |
| // Observe elements for animation | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const animatedElements = document.querySelectorAll('.stagger-animation > *, section > div'); | |
| animatedElements.forEach(el => { | |
| if (!el.closest('.carousel-container')) { | |
| observer.observe(el); | |
| } | |
| }); | |
| }); | |
| // 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) { | |
| target.scrollIntoView({ | |
| behavior: 'smooth', | |
| block: 'start' | |
| }); | |
| } | |
| }); | |
| }); | |
| // Parallax effect for hero section | |
| window.addEventListener('scroll', () => { | |
| const scrolled = window.pageYOffset; | |
| const parallaxElements = document.querySelectorAll('.hero-parallax'); | |
| parallaxElements.forEach(element => { | |
| const speed = element.dataset.speed || 0.5; | |
| const yPos = -(scrolled * speed); | |
| element.style.transform = `translateY(${yPos}px)`; | |
| }); | |
| }); | |
| // Mobile menu interactions | |
| document.addEventListener('DOMContentLoaded', () => { | |
| // Initialize Feather icons | |
| feather.replace(); | |
| // Add loading states to buttons | |
| const buttons = document.querySelectorAll('button'); | |
| buttons.forEach(button => { | |
| button.addEventListener('click', function() { | |
| if (!this.classList.contains('loading')) { | |
| this.classList.add('loading-pulse'); | |
| setTimeout(() => { | |
| this.classList.remove('loading-pulse'); | |
| }, 1000); | |
| } | |
| }); | |
| }); | |
| // Handle newsletter subscription | |
| const newsletterForms = document.querySelectorAll('form'); | |
| newsletterForms.forEach(form => { | |
| form.addEventListener('submit', (e) => { | |
| e.preventDefault(); | |
| const email = form.querySelector('input[type="email"]'); | |
| if (email && email.value) { | |
| // Show success message | |
| const successMessage = document.createElement('div'); | |
| successMessage.className = 'fixed top-4 right-4 bg-green-500 text-white px-6 py-3 rounded-lg shadow-lg z-50'; | |
| successMessage.textContent = 'Inscription réussie !'; | |
| document.body.appendChild(successMessage); | |
| setTimeout(() => { | |
| successMessage.remove(); | |
| }, 3000); | |
| form.reset(); | |
| } | |
| }); | |
| }); | |
| }); | |
| // Image lazy loading | |
| if ('IntersectionObserver' in window) { | |
| const imageObserver = new IntersectionObserver((entries, observer) => { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| const img = entry.target; | |
| img.src = img.dataset.src || img.src; | |
| img.classList.remove('loading'); | |
| imageObserver.unobserve(img); | |
| } | |
| }); | |
| }); | |
| document.querySelectorAll('img[data-src]').forEach(img => { | |
| imageObserver.observe(img); | |
| }); | |
| } |