a random cycling images gallery

In previous post I post the images gallery auto change images, and when You just need add one more sentence, so you images gallery will random  and auto change it is more better. The previous post gallery change the pictures in arrays order.

here is the source code:

var i =0;
function rotate1(){
    var imgArray = new Array(“aphex”,”addiction”,”amy”,”abba”,”donna”,”elliott”,”fergie”);
    picName=imgArray[i];
   //random chose a images index
   i = Math.floor(Math.random()*imgArray.length);
   document.getElementById(‘picture1’).style.backgroundImage = “url(images/product/”+ picName +”.jpg)”;
   ( i == (imgArray.length – 1 )) ? i = 0 : i++;
}
window.setInterval(rotate1, 2000);

function rotate2(){
    var imgArray = new Array(“aphex”,”addiction”,”amy”,”abba”,”donna”,”elliott”,”fergie”);
   picName=imgArray[i];
   //random chose a images index
   i = Math.floor(Math.random()*imgArray.length);
   document.getElementById(‘picture2’).style.backgroundImage = “url(images/product/”+ picName +”.jpg)”;
   ( i == (imgArray.length – 1 )) ? i = 0 : i++;
}
window.setInterval(rotate2, 1500);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s