0
On image slider generation
How to use JavaScript to developed a simple image slider
2 Respuestas
+ 1
1.Insert following code in HTML file
<button id="prev" onclick="previous()">Prev</button>
<img class="image" src="img/1.jpg" id="slider">
<button id="next" onclick="next()">Next</button>
2. Now in JavaScript:
var images = ["img/1.jpg",
"img/2.jpg",
"img/3.jpg"
];
var num = 0;
var t = setInterval(next, 7000);
function previous() {
var slider = document.getElementById("slider");
num--;
if (num < 0) {
num = images.length - 1;
}
slider.src = images[num];
}
function next() {
var slider = document.getElementById("slider");
num++;
if (num > images.length - 1) {
num = 0;
}
slider.src = images[num];
}