I am trying to create a slider, and there is a button that I am using for moving the elements to the left. It works, but only once. After that the click has no effect. Here is my code below
HTML
<section class="section3">
<button class="left">LEFT</button> <!-- button that I click on to move elements to the left -->
<div class="carousel-container">
<div class="corousel-element">1</div>
<div class="carousel-element">2</div>
<div class="carousel-element">3</div>
<div class="carousel-element">4</div>
<div class="carousel-element">5</div>
<div class="carousel-element">6</div>
<div class="carousel-element">7</div>
<div class="carousel-element">8</div>
<div class="carousel-element">9</div>
<div class="carousel-element">10</div>
<div class="carousel-element">11</div>
<div class="carousel-element">12</div>
<div class="carousel-element">13</div>
</div>
</section>
CSS(SASS)
section.section3 {
overflow: hidden;
div.carousel-container {
display: flex;
overflow: hidden;
justify-content: center;
div.carousel-element {
width: 169px;
height: 193px;
background: blue;
flex-shrink: 0;
}
div.corousel-element:not(:first-child) {
margin-left: 15px;
}
}
}
JAVASCRIPT
var buttonLeft = document.querySelector(".left"); // left button
var carouselContainer = document.querySelector(".corousel-container"); // carousel-container
function left() {
carouselContainer.style.transform = "translate(-20px)"; // here I am trying to move elements to left with translate.
}
buttonLeft.addEventListener("click", left);