Bom dia, alguém pode me auxiliar para funcionar um script. Estou tentando rodar 6 imagens, pois não consegui aprender como se faz o loop ou refresh de imagem. A função sozinha já consigo rolar 2 imagens. Fica assim: <script type="text/javascript">
window.onload = function(){
setInterval("TrocaImagem()",5000); // troca imagem a cada 3 segundos
}
function TrocaImagem(){
var imagem = document.getElementById('img').src;
if(imagem.indexOf("img1.jpg") != -1){
document.getElementById('img').src = "imagem01.gif";
}else{
document.getElementById('img').src = "imagem02.gif";
}
}
</script>
========= CODIGO HTML ONDE A FUNÇÃO ENTRA
<img "img1.jpg" id="img">
===================================
Essa primeira parte funcionou perfeitamente, atendeu as minhas espectativas quanto ao script, o problema ocorreu quando eu tentei manipular mais 2 funções
-----------------------------------------------------------------
Onde ocorre o erro:
<script type="text/javascript">
funcao1(){
setInterval("TrocaImagem1()",5000); // troca imagem a cada 3 segundos
}
function TrocaImagem1(){
var imagem = document.getElementById('img').src;
if(imagem.indexOf("img1.jpg") != -1){
document.getElementById('img').src = "imagem01.gif";
}else{
document.getElementById('img').src = "imagem02.gif";
}
}
}
funcao2(){
setInterval("TrocaImagem2()",5000); // troca imagem a cada 3 segundos
}
function TrocaImagem2(){
var imagem = document.getElementById('img').src;
if(imagem.indexOf("img2.jpg") != -1){
document.getElementById('img').src = "imagem03.gif";
}else{
document.getElementById('img').src = "imagem04";
}
}
}
funcao3(){
setInterval("TrocaImagem3()",5000); // troca imagem a cada 3 segundos
}
function TrocaImagem3(){
var imagem = document.getElementById('img').src;
if(imagem.indexOf("img3.jpg") != -1){
document.getElementById('img').src = "imagem05.gif";
}else{
document.getElementById('img').src = "imagem06.gif";
}
}
window.onload = function(){
funcao1();
funcao2();
funcao3();
}
</script> ---------------------------------------------------------------- ME AJUDEM A ARRUMAR ESSE SCRIPT, POIS não conheço uma forma de atualizar uma imagem.