click event listener automatically triggering

hey folks can anyone check this pen out the click event listener attached to slider in this code is automatically triggering which is supposed to only trigger when I click the slider. https://codepen.io/adityakirad/pen/oNQPEGW
3 Replies
Jochem
Jochem17mo ago
you're triggering the click yourself: next.click();
Aditya Kirad
Aditya KiradOP17mo ago
oh yeah thank you so much for pointing this error out
Jochem
Jochem17mo ago
also, this:
function pauseAutoplay() {
clearInterval(autoplayInterval);
console.log("Slider AutoPlay Is Paused");
}
//Pause slider autoplay when its hovered
slider?.addEventListener("click", () => {
pauseAutoplay();
console.log("autoplay is paused");
});
function pauseAutoplay() {
clearInterval(autoplayInterval);
console.log("Slider AutoPlay Is Paused");
}
//Pause slider autoplay when its hovered
slider?.addEventListener("click", () => {
pauseAutoplay();
console.log("autoplay is paused");
});
You can just write like this
function pauseAutoplay() {
clearInterval(autoplayInterval);
console.log("Slider AutoPlay Is Paused");
}
//Pause slider autoplay when its hovered
slider?.addEventListener("click", pauseAutoplay);
function pauseAutoplay() {
clearInterval(autoplayInterval);
console.log("Slider AutoPlay Is Paused");
}
//Pause slider autoplay when its hovered
slider?.addEventListener("click", pauseAutoplay);
if you don't mind losing the console.log, which exists in the pauseAutoplay function anyway. Note the lack of () if you're just passing it the function
Want results from more Discord servers?
Add your server