Skip to main content
2 de 6
code snippet
William Pereira
  • 4,2mil
  • 4
  • 28
  • 50

var slide = ["procurando_dory.jpg","big_buck_bunny.jpg","madagascar_2.jpg","monstros_sa_2.jpg"];
var i = 5;
function clic() 
{
    var randomize = Math.floor((Math.random() * slide.length));
    document.getElementById('fig').innerHTML = '<img src=\"https://sites.google.com/site/mplayerplugin/repositorio/' + slide[randomize] + '\" />';
    var intervalo = setInterval(function()
    {
        document.getElementById('txt').textContent = i;
        i--;
        if(i < 0)
        {
            clearInterval(intervalo);
            limpar();
            i = 5;
            document.getElementById('txt').textContent = 0;
        };
    }, 5000); // Define os 5 segundos para limpar
};

function limpar() 
{
    document.getElementById('fig').innerHTML = ''; // Esvazia a div id='fig'
};
<center>
    <div id="fig"> &nbsp; </div>
    <span id="txt"> &nbsp; </span>
    <hr size="1" color="silver">
    <input type="button" onclick="clic()" value="Aperte!" id="troca" />
</center>

user31050
  • 440
  • 4
  • 12