Results 1 to 3 of 3

Thread: Fade-in slideshow - Random output

  1. #1
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Fade-in slideshow - Random output

    I love this script - I've got it creating an array from multiple Cold Fusion Queries.

    My request is for code that will randomize the display order of the images in the array. I've ben rackin' my brain on that one for a bit.

    Thanks!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Random means random. This means any slide can follow any slide, this can result in repeats (which will look like the show is not doing anything for a period at least twice as long as the configured pause) and repeated alternations at times, especially if the total number of slides is low. With that in mind, add below the 'NO need to edit beyond here' line:

    Code:
    ////NO need to edit beyond here/////////////
    
    //Randomizing Unit Courtesy of Mike Winter as seen at:
    //http://www.dynamicdrive.com/forums/showthread.php?p=8442
    function random(n) {
      return Math.floor((Math.random() % 1) * n);
    }
    
    Array.prototype.shuffle = function() {var i = this.length;
      while(i--) {this.swap(i, random(i + 1));}
    };
    Array.prototype.swap = function(x, y) {
      var t = this[x]; this[x] = this[y]; this[y] = t;
    };
    //End Randomizing Unit
    
    fadeimages.shuffle();
    Put this (highlight red) in the insertimage function:

    Code:
    function insertimage(i){
    fadeimages.shuffle();
    var tempcontainer=fadeimages[i][1]!=""? '<a href="'+fadeimages[i][1]+'" target="'+fadeimages[i][2]+'">' : ""
    tempcontainer+='<img src="'+fadeimages[i][0]+'" border="0">'
    tempcontainer=fadeimages[i][1]!=""? tempcontainer+'</a>' : tempcontainer
    return tempcontainer
    }
    I highly recommend that you use this with at least 10 images, any less than that will probably have too many repeats and repeat alternations (going back and forth between just two slides for an extended time).
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Worked BEAUtifuly - Thank You!!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •