equipo.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const carouselTrack = document.querySelector('.carousel-track');
  2. const cards = Array.from(document.querySelectorAll('.card-car'));
  3. const prevBtn = document.getElementById('prevBtn');
  4. const nextBtn = document.getElementById('nextBtn');
  5. const totalCards = cards.length;
  6. let currentIndex = 0;
  7. const visibleCards = 0; // Número de tarjetas visibles
  8. const cardWidth = 200; // Ancho de cada tarjeta
  9. // Inicializa el carrusel
  10. function initializeCarousel() {
  11. showCard(currentIndex);
  12. }
  13. // Función para mover el carrusel
  14. function showCard(index) {
  15. const offset = (index - Math.floor(visibleCards / 2)) * cardWidth;
  16. carouselTrack.style.transform = `translateX(${-offset}px)`;
  17. updateCardColors(index);
  18. }
  19. // Función para actualizar las clases de color
  20. function updateCardColors(index) {
  21. cards.forEach((card, i) => {
  22. card.classList.remove('active');
  23. // Asegura que la tarjeta del medio sea siempre a color
  24. if (i === index+3) {
  25. card.classList.add('active');
  26. }
  27. });
  28. }
  29. // Función para cambiar el índice y mostrar la nueva tarjeta
  30. function changeIndex(direction) {
  31. if (direction === 'next') {
  32. currentIndex = (currentIndex + 1) % totalCards;
  33. } else if (direction === 'prev') {
  34. currentIndex = (currentIndex - 1 + totalCards) % totalCards;
  35. }
  36. showCard(currentIndex);
  37. }
  38. nextBtn.addEventListener('click', () => {
  39. changeIndex('next');
  40. });
  41. prevBtn.addEventListener('click', () => {
  42. changeIndex('prev');
  43. });
  44. initializeCarousel();