prev_btn and next_btn are the functions it triggered when someone click the buttons
let i = 0;
function prev_btn() {
console.log("Previous button Clicked");
i--;
if (i < 1) {
i = 5;
}
console.log(i);
preview();
}
function next_btn() {
console.log("Next button Clicked");
i++;
if (i > 5) {
i = 1;
}
console.log(i);
preview();
}
function preview() {
let img = document.getElementById("slider_img").setAttribute("src", `Slider/img${i}.jpg`);
}
Just want to make slider and its working but I need better way to do this
2
Answers
Although you have not post what exactly you want and i do not have your code to get the concept of you script. I think hereby you can make your current code more dynamic.
the correct and classic way to do that: