From 93861389a964bdabe6f0912e0d65020ca0a16176 Mon Sep 17 00:00:00 2001 From: sheva Date: Fri, 22 Sep 2023 16:27:29 +0300 Subject: [PATCH] fixed slider --- src/index.html | 43 ++++++++----------------------------------- src/scripts/main.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/index.html b/src/index.html index 30409c25e3..663c7b6afa 100644 --- a/src/index.html +++ b/src/index.html @@ -87,8 +87,14 @@

We believe in the power of bold ideas that can solv
- - + +

INtro

@@ -464,38 +470,5 @@

our socials

type="text/javascript" src="scripts/main.js" > - diff --git a/src/scripts/main.js b/src/scripts/main.js index 67965aa358..203093b4ef 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -31,3 +31,34 @@ form.addEventListener('submit', (e) => { form.reset(); window.scrollTo(0, 0); }); + +const prevButton = document.querySelector('.slider__button--left'); +const nextButton = document.querySelector('.slider__button--right'); +let slideIndex = 0; + +showSlides(slideIndex); + +function plusSlide(n) { + showSlides((slideIndex += n)); +} + +function showSlides(n) { + const slides = document.querySelectorAll('.slider__image'); + + if (n > slides.length - 1) { + slideIndex = 0; + } + + if (n < 0) { + slideIndex = slides.length - 1; + } + + for (let i = 0; i < slides.length; i++) { + slides[i].style.display = 'none'; + } + + slides[slideIndex].style.display = 'block'; +} + +prevButton.addEventListener('click', () => plusSlide(-1)); +nextButton.addEventListener('click', () => plusSlide(1));