Well, random is random, which means that sometimes you could get the same order two times in a row. And I suppose it wouldn't matter what order the images were in to begin with, but that could be randomized too.
That said, there are two other aspects of this that are tricky.
- Since we will be shuffling at the end of each rotation, if the last image isn't a static one, it will jump to its new image. I put in some code that will enforce that the last image be static.
- I can't figure out why yet, but there must be an even number of images, otherwise there will be a blank image at the end of every other rotation.
Here's an example initialization (addition highlighted):
Code:
var mygallery2=new fadeSlideShow({
wrapperid: "fadeshow2", //ID of blank DIV on page to house Slideshow
dimensions: [250, 180], //width/height of gallery in pixels. Should reflect dimensions of largest image
imagearray: [
["11l7ls0.jpg", "", "", "Nothing beats relaxing next to the pool when the weather is hot."],
["xp3hns.jpg", "http://en.wikipedia.org/wiki/Cave", "_new", "Some day I'd like to explore these caves!"],
["531q3n.jpg"],
["119w28m.jpg", "", "", "What a beautiful scene with everything changing colors."],
["stadium.jpg"],
["lakeside.jpg"] //<--no trailing comma after very last image element!
],
displaymode: {type:'auto', pause:2500, cycles:0, wraparound:false},
persist: false, //remember last viewed slide and recall within same session?
fadeduration: 500, //transition duration (milliseconds)
descreveal: "none",
togglerid: "",
onslide: function(curimage, index){
var ims = this.setting.imagearray, i = ims.length - 1;
if(index == i){
var statNums = [1, 3], $ = jQuery, stat = [], rand = [];
statNums.push(i + 1);
$(ims).each(function(i){
if($.inArray(i + 1, statNums) > -1){
stat[i] = this;
} else {
rand.push(this);
}
});
rand.sort(function(){return 0.5 - Math.random();});
for (i; i > -1; --i){
if(stat[i]){
ims[i] = stat[i];
} else {
ims[i] = rand.pop();
}
}
this.setting.$gallerylayers.html(fadeSlideShow.routines.getFullHTML(ims)).find('img').hide().eq(this.setting.curimage).show();
}
}
})
Don't miss the added comma (red) after the togglerid entry. The red numbers 1 and 3 assigned to the statNums array are the images that will be static, add as many numbers here as you like. 1 represents the first image and so on.
Bookmarks