lundi 4 janvier 2016

Javascript Random Image by Time

I'm tring to show images randomly by the time. But I need a different thing.

var images = []
images[0] = "img/y0.gif";
images[1] = "img/y1.gif";
images[2] = "img/y2.gif";
images[3] = "img/y3.gif";
images[4] = "img/y4.gif";

images[5] = "img/1.jpg";
images[6] = "img/2.jpg";
images[7] = "img/3.jpg";

usedImages = [];
setInterval(function () {changeImage();},100);

var changeImage = function () {
    var index = Math.floor(Math.random() * (images.length)),
    thisImage = images[index];

    usedImages.push(thisImage);
    images.splice(index, 1);

    if (images.length < 1) {
        images = usedImages.splice(0, usedImages.length);
    }

    var imgStr = '<img src="' + thisImage + '" alt = "">';
    document.write(imgStr); 
    document.close();
}           

My codes work but if the image is a gif interval time must be 500, or if the image is image[2] time must be 500.

How can I do it?

Thanks..




Aucun commentaire:

Enregistrer un commentaire