PDA

View Full Version : Random Pic Question



Niko
06-20-2010, 03:51 PM
1) Script Title: Ultimate Fade In Slideshow v2.0-

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm

3) Describe problem: Within Ultimate Fade In Slideshow v2.0- there is an option for randomization of pictures.

Is if possible to have Ultimate Fade In randomize two pictures out of three. Meaning, when viewing the slide show the first and forth picture are the same but the second and third are random.
Ex: non-random/random/random/non-random/random/random/non-random and so on..

TIA!

jscheuer1
06-22-2010, 09:02 AM
Yes. Do you mean random each rotation, or random each page load?

Niko
06-22-2010, 09:38 AM
Random each rotation, but for every third picture be non-random (a static picture). So, you would have a static picture then random each rotation for two pictures then back to a static picture then random each rotation and so on...1 static pic, 2 random pics, 1 static pic, 2 random pics so on...

jscheuer1
06-22-2010, 04:21 PM
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):


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.

Niko
06-23-2010, 11:10 PM
Thank You!

I haven't been able to get your script to work. The pictures don't rotate in a random order. But I will continue to work on it. For a better idea on what I'm working please see below:



["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"],
["11l7ls0.jpg", "", "", "Nothing beats relaxing next to the pool when the weather is hot."],
["stadium.jpg"],
["lakeside.jpg"],
["11l7ls0.jpg", "", "", "Nothing beats relaxing next to the pool when the weather is hot."],
["lakeside.jpg"],
["lakeside.jpg"] //<--no trailing comma after very last image element!

And so on.....

Red=Static (create a Static Folder/copy&paste 11l7ls0.jpg to that folder)
Blue=Random (create a Random Folder/copy&paste the rest of the images)

Anytime an image is picked from the Random folder it should be a random pick.

jscheuer1
06-24-2010, 12:38 AM
I tested this rather extensively. The code you provide in your post only reveals the local names (I'm assuming of some) of the images you want displayed. It doesn't show me anything I can use to diagnose why you are not getting the result you want.

If you want more help:

Please post a link to a page on your site that contains the problematic code so we can check it out.

As a side note, I was playing with the code a bit more, and it can be set up so that every third image is static, the rest shuffled on each rotation, regardless of how many images there are, without any need to specify the statNum array.

But lets not get ahead of ourselves. First lets see if we can figure out why this isn't working for you.

Give me a link to the problem page and I will check it out.

Niko
06-25-2010, 09:46 PM
I just got back to working on this and I was able to resolve the error and both were cuased by me.

1) make sure to copy the entire code
2) wait one rotation before the pictures are random ( I was thinking that it would be random the first time around)
3) and did I mention that it really helps when you copy the entire code

Thank You...u-da-man!