I wondering what’s wrong with my code but can’t figure out what’s going on.
here is the JS
const slider = document.querySelector('.slider');
let newTranslate = 0
const next = () => {
newTranslate -= 100
slider.style.transform = `translateX(${newTranslate}%)`
};
const prev = () => {
newTranslate += 100
slider.style.transform = `translateX(${newTranslate}%)`
};
and my HTML
<section class="quote">
<a onclick="prev()">
<i class="arrow arrow-left"></i>
</a>
<div class="slider-container slider-1">
<div class="slider">
<div class="slide slide-1">
<div class="quote_container">
...
</div>
</div>
</div>
</div>
<a onclick="next()">
<i class="arrow arrow-right"></i>
</a>
</section>
What is strange is that next() is working good but prev only working once after the page is loaded. When i click next() and then prev(), prev() is not working.
When i run the function in the console it’s working perfectly.
It seems there is no async element so i dont understand at all.
Someone could help ?
Thanks a lot
3
Answers
It might width parent tag is not enough to move the icon. Also with the slider element, I think u using the id for that element if right u missing the ‘#’ prefix. It should be:
Its because your slider element is above the left arrow (prev()) in the stack, so when it shifts left it sits on top and thus blocks your click. Just set the links to be
position:relative
with az-index:1
(or higher than the slider) and it should work