Results 1 to 5 of 5

Thread: Ultimate Fade-In Slideshow - limiting number of random slides

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

    Default Ultimate Fade-In Slideshow - limiting number of random slides

    1) Script Title: Ultimate Fade-In slide show

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...nslideshow.htm

    3) Describe problem:

    Hello. Great script. Works brilliantly, however, I was just wondering if anyone had produced a solution whereby a limited number of random slides are selected for display?

    For example,

    Code:
    imagearray: [
     ["image1.jpg", "http://site1.com"],
     ["image2.jpg", "http://site2.com"],
     ["image3.jpg", "http://site3.com"],
     ["image4.jpg", "http://site4.com"],
     ["image5.jpg", "http://site5.com"],
     ["image6.jpg", "http://site6.com"],
     ["image7.jpg", "http://site7.com"]
    ],
    But just select 4 slides from the 7 to display.

    It seems easy enough to select random elements to insert in the imagearray[], aside from adding no trailing , to the final element.

    Many thanks!
    Last edited by jscheuer1; 10-18-2012 at 02:40 PM. Reason: Format

  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

    Just add the highlighted:

    Code:
    imagearray: [
     ["image1.jpg", "http://site1.com"],
     ["image2.jpg", "http://site2.com"],
     ["image3.jpg", "http://site3.com"],
     ["image4.jpg", "http://site4.com"],
     ["image5.jpg", "http://site5.com"],
     ["image6.jpg", "http://site6.com"],
     ["image7.jpg", "http://site7.com"]
    ].sort(function(){return 0.5 - Math.random();}).slice(0, 4),
    The browser cache may need to be cleared and/or the page refreshed to see changes.

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

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

  3. #3
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <script  type="text/javascript">
    
    var A1= [
     ["image1.jpg", "http://site1.com"],
     ["image2.jpg", "http://site2.com"],
     ["image3.jpg", "http://site3.com"],
     ["image4.jpg", "http://site4.com"],
     ["image5.jpg", "http://site5.com"],
     ["image6.jpg", "http://site6.com"],
     ["image7.jpg", "http://site7.com"]
    ]
    
    function shuffle(ary){
      for (var r,t,z0=0;z0<ary.length;z0++){
       r=Math.floor(Math.random()*ary.length);
       t=ary[z0];
       ary[z0]=ary[r];
       ary[r]=t;
      }
      return ary;
     }
    
     A1=shuffle(A1);
    
     A1.length=4;
    
    alert(A1.join('\n'));
    
    //then use
    //imagearray:A1,
    
    </script>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  4. #4
    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

    Mine is simpler:

    Code:
    imagearray: [
     ["image1.jpg", "http://site1.com"],
     ["image2.jpg", "http://site2.com"],
     ["image3.jpg", "http://site3.com"],
     ["image4.jpg", "http://site4.com"],
     ["image5.jpg", "http://site5.com"],
     ["image6.jpg", "http://site6.com"],
     ["image7.jpg", "http://site7.com"]
    ].sort(function(){return 0.5 - Math.random();}).slice(0, 4),
    - John
    ________________________

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

  5. #5
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Many thanks, both of you, for your help. The solution works a treat.

    Thanks again.

Similar Threads

  1. Ultimate Fade In Slideshow v2.1 help to increase # of slides
    By chikki2 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 03-18-2011, 03:04 PM
  2. Replies: 4
    Last Post: 08-15-2010, 11:34 PM
  3. Ultimate Fade-in slideshow (v2.1) - navigation to specific slides
    By alison985 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 05-19-2010, 12:38 AM
  4. Random Display in Ultimate Fade-in slideshow (v2.0)
    By psellers in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 09-24-2009, 08:02 PM
  5. Conveyor Belt Slideshow Script - number showing between slides
    By Jim81501 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 07-24-2009, 08:50 PM

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
  •