From cc11eb73897505665e75e485afedb581f8459fad Mon Sep 17 00:00:00 2001 From: Peter Mazarovich Date: Sat, 17 Feb 2024 15:48:39 +0300 Subject: [PATCH] Event handlers --- 5-module/1-task/index.js | 3 ++- 5-module/2-task/index.js | 6 +++++- 5-module/3-task/index.js | 31 ++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/5-module/1-task/index.js b/5-module/1-task/index.js index c94c28a..0b30b93 100644 --- a/5-module/1-task/index.js +++ b/5-module/1-task/index.js @@ -1,3 +1,4 @@ function hideSelf() { - // ваш код... + let element = document.querySelector(".hide-self-button"); + element.addEventListener('click', () => element.hidden = true); } diff --git a/5-module/2-task/index.js b/5-module/2-task/index.js index 7a8a3b8..9aef574 100644 --- a/5-module/2-task/index.js +++ b/5-module/2-task/index.js @@ -1,3 +1,7 @@ function toggleText() { - // ваш код... + const element = document.querySelector('.toggle-text-button'); + element.addEventListener('click', () => { + const text = document.querySelector('#text'); + text.hidden = !text.hidden; + }); } diff --git a/5-module/3-task/index.js b/5-module/3-task/index.js index 26a2fc6..9d3ca94 100644 --- a/5-module/3-task/index.js +++ b/5-module/3-task/index.js @@ -1,3 +1,32 @@ function initCarousel() { - // ваш код... + const leftArrow = document.querySelector('.carousel__arrow_left'); + const rightArrow = document.querySelector('.carousel__arrow_right'); + const carouselInner = document.querySelector('.carousel__inner'); + const offsetWidth = carouselInner.offsetWidth; + let currentSlide = 0; + function checkVisibility() { + if (currentSlide < 3 && currentSlide > 0) { + leftArrow.style.display = ''; + rightArrow.style.display = ''; + } else if (currentSlide === 3) { + rightArrow.style.display = 'none'; + } else if (currentSlide === 0) { + leftArrow.style.display = 'none'; + } + } + checkVisibility(); + leftArrow.addEventListener('click', () => { + if (currentSlide > 0) { + currentSlide -= 1; + carouselInner.style.transform = `translateX(-${currentSlide * offsetWidth}px)`; + } + checkVisibility(); + }); + rightArrow.addEventListener('click', () => { + if (currentSlide < 3) { + currentSlide += 1; + carouselInner.style.transform = `translateX(-${currentSlide * offsetWidth}px)`; + } + checkVisibility(); + }); }