main.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. const hamburger = document.querySelector('.hamburger');
  2. const mobileMenu = document.querySelector('.mobile-menu');
  3. const year = document.getElementById('year');
  4. const currentYear = new Date().getFullYear();
  5. year.textContent = currentYear;
  6. hamburger.addEventListener('click', () => {
  7. mobileMenu.classList.toggle('active');
  8. });
  9. window.addEventListener('resize', () => {
  10. if (window.innerWidth > 1300) {
  11. mobileMenu.classList.remove('active');
  12. }
  13. });
  14. // ---------------- del carrusel ----------------
  15. let index = 0;
  16. function showSlide(n) {
  17. const slides = document.querySelectorAll('.slide');
  18. if (n >= slides.length) index = 0;
  19. if (n < 0) index = slides.length - 1;
  20. const newTransformValue = -index * 100 + '%';
  21. document.querySelector('.slider-container').style.transform = `translateX(${newTransformValue})`;
  22. }
  23. function moveSlide(step) {
  24. showSlide(index += step);
  25. }
  26. showSlide(index);
  27. setInterval(() => moveSlide(1), 8000);
  28. window.onscroll = function () {
  29. let scrollBtn = document.getElementById("scrollToTopBtn");
  30. if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
  31. scrollBtn.style.display = "block";
  32. } else {
  33. scrollBtn.style.display = "none";
  34. }
  35. };
  36. function scrollToTop() {
  37. window.scrollTo({ top: 0, behavior: 'smooth' });
  38. }
  39. // carrusel de personas
  40. const carouselTrack = document.querySelector('.carousel-track');
  41. const cards = document.querySelectorAll('.card-car');
  42. const prevBtn = document.getElementById('prevBtn');
  43. const nextBtn = document.getElementById('nextBtn');
  44. let currentIndex = 0;
  45. const totalCards = cards.length;
  46. movePercent = 100 / totalCards;
  47. function showCard(index) {
  48. carouselTrack.style.transform = `translateX(${-index * movePercent}%)`;
  49. }
  50. prevBtn.addEventListener('click', () => {
  51. currentIndex = (currentIndex > 0) ? currentIndex - 1 : totalCards - 1;
  52. showCard(currentIndex);
  53. });
  54. nextBtn.addEventListener('click', () => {
  55. currentIndex = (currentIndex < totalCards - 1) ? currentIndex + 1 : 0;
  56. showCard(currentIndex);
  57. });
  58. setInterval(() => {
  59. currentIndex = (currentIndex < totalCards - 1) ? currentIndex + 1 : 0;
  60. showCard(currentIndex);
  61. }, 5000);
  62. // ---------------- del carrusel de quipos ----------------