+ 2
I have to change seven different images .How I do that?
3 Respuestas
+ 3
Like a slide? It change one after another one. Is that what you meant?
0
Using setInterval to change images in fixed interval.
Here an example
var imgs = [
"https://via.placeholder.com/468x300?text=Image+1",
"https://via.placeholder.com/468x300?text=Image+2",
"https://via.placeholder.com/468x300?text=Image+3",
"https://via.placeholder.com/468x300?text=Image+4",
"https://via.placeholder.com/468x300?text=Image+5",
"https://via.placeholder.com/468x300?text=Image+6",
"https://via.placeholder.com/468x300?text=Image+7",
"https://via.placeholder.com/468x300?text=Image+8"
];
var count = 1;
setInterval(chgimg,1000);
function chgimg(){
var img = document.querySelector("#img");
img.src = imgs[count++];
if(count>=imgs.length) count = 0;
}
https://code.sololearn.com/WBfwsYQADhdz/?ref=app