let currentIndex = 0; const slides = document.querySelectorAll('.slide'); const slideshow = document.getElementById('slideshow'); const totalSlides = slides.length; const dotsContainer = document.querySelector('.dots'); let startX; let isDragging = false; // Create navigation dots function createDots() { for (let i = 0; i < totalSlides; i++) { const dot = document.createElement('div'); dot.classList.add('dot'); if (i === currentIndex) { dot.classList.add('active'); } dotsContainer.appendChild(dot); } } function updateDots() { const dots = document.querySelectorAll('.dot'); dots.forEach((dot, index) => { dot.classList.toggle('active', index === currentIndex); }); } const slidesContainer = document.querySelector('.slides-container'); function updateSlidePosition() { const offset = -currentIndex * 100; // Az aktív dia vízszintes eltolása slidesContainer.style.transform = `translateX(${offset}%)`; updateDots(); } function showPreviousSlide() { if (currentIndex > 0) { currentIndex--; updateSlidePosition(); } } function showNextSlide() { if (currentIndex < totalSlides - 1) { currentIndex++; updateSlidePosition(); } } // Initialize the slide position and dots createDots(); updateSlidePosition(); // Touch events slideshow.addEventListener('touchstart', (event) => { startX = event.touches[0].clientX; isDragging = true; }); slideshow.addEventListener('touchmove', (event) => { if (!isDragging) return; const currentX = event.touches[0].clientX; const diffX = currentX - startX; if (Math.abs(diffX) > 30) { // Csökkentettük az érzékenységi küszöböt if (diffX > 0) { showPreviousSlide(); } else { showNextSlide(); } isDragging = false; } }); slideshow.addEventListener('touchend', () => { isDragging = false; }); // Mouse events slideshow.addEventListener('mousedown', (event) => { startX = event.clientX; isDragging = true; }); slideshow.addEventListener('mousemove', (event) => { if (!isDragging) return; const currentX = event.clientX; const diffX = currentX - startX; if (Math.abs(diffX) > 30) { // Csökkentettük az érzékenységi küszöböt if (diffX > 0) { showPreviousSlide(); } else { showNextSlide(); } isDragging = false; } }); slideshow.addEventListener('mouseup', () => { isDragging = false; }); slideshow.addEventListener('mouseleave', () => { isDragging = false; });