2
Well my question is the following, I would like to know, how would you make javascript take a 5 seconds interval before editing image.
My code:
window.onload = function() {
if(2>1){
document.getElementById("imagem").src = "https://placeholdit.imgix.net/~text?txtsize=36&txt=Imagem+1&w=350&h=150";
document.getElementById("imagem2").src = "https://placeholdit.imgix.net/~text?txtsize=36&txt=Imagem+2&w=350&h=150";
document.getElementById("imagem3").src = "https://placeholdit.imgix.net/~text?txtsize=36&txt=Imagem+3&w=350&h=150";
}
}
<img id="imagem" src="https://placeholdit.imgix.net/~text?txtsize=36&txt=Imagem+1&w=350&h=150">
<img id="imagem2" src="https://placeholdit.imgix.net/~text?txtsize=36&txt=Imagem+2&w=350&h=150">
<img id="imagem3" src="https://placeholdit.imgix.net/~text?txtsize=36&txt=Imagem+3&w=350&h=150">
That is to say that there was an interval in each src of 5 seconds.
First javascript edit the id "image", after 5 seconds edit the id "imagem2", etc...
I’m sorry, but I’m bit novice in the area of javascript, say-m and one thing, if I want to add more images to edit different id’s how do?
– Gonçalo
Opa @Gonçalo, what data do you have? Do you have an array of images? How many images do you want to add at a time?
– KaduAmaral
Well I will try to explain it very well, it works as follows: I have an img of light yellow, an img of light green, an img of light orange, a light purple img and a light red img, ai type if the color condition is equal to red, I want to simulate that it goes through all the colors until it gets red, which is a roulette wheel, which basically shows the image of dark green > shows the image of light green, wait 1 second, active shows dark orange image > shows light orange image etc... until you get to red
– Gonçalo
Hmm. I get it @Gonçalo You need to do this with pure Javascript or you can use some library like jQuery?
– KaduAmaral
I can use Jquery, no problem.
– Gonçalo
@Gonçalo, I added a link to the answer. ;)
– KaduAmaral
Friend just tell me one thing, this works on the same img id?
– Gonçalo
Yes @Gonçalo, you can do it direct
document.getElementById(id).setAttribute('src', 'caminho/da/imagem.jpg');
– KaduAmaral
I’ve got it Thank you!
– Gonçalo