Results 1 to 8 of 8

Thread: rotating images (no link)

  1. #1
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default rotating images (no link)

    This is my code below. I LOVE everything about it, border and all.

    However, this only randomly changes when I reload the page.

    Is there a way I can make it so that the images keep rotating when I'm on the page instead of it randomly changing everytime I reload?

    I would like to keep the border and size and all.

    I REALLY NEED HELP!!!! THANK YOU SO MUCH IN ADVANCE!



    <script type="text/javascript">
    /*********Edit values here for your pictures*******************/
    var
    pic1='https://store-a32dc.mybigcommerce.com/product_images/uploaded_images/MOMSHOPPING2.gif',
    pic2='https://store-a32dc.mybigcommerce.com/product_images/uploaded_images/RRR.gif',
    pic3='https://store-a32dc.mybigcommerce.com/product_images/uploaded_images/2photos.jpg';
    /***************End of Edit*********************************/

    var rangPics=[pic1,pic2,pic3]; // Add all the picture variables in this array.
    window.onload=function() { rangRandom=Math.floor(Math.random()*rangPics.length);
    document.getElementById('show').innerHTML='<img src="'+rangPics[rangRandom]+'" alt="myimage" style="width:950px;height:450px;">';}</script>
    <div id="show" style="text-align:center;width:950px;border:3px double #222;padding:10px;"></div>

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    This code is very simple: it isn't designed to do that. There are, however, other scripts available (search the DD library) that will do this. Look for a simple image slideshow that allows random order.
    You could try to add extra code to the current example: basically create an infinite loop with a 5 second pause that executes the same code as the onload function above. But it's probably easier to just use an existing script rather than writing that.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Is there a way I can add extra code to the current example?

    Would appreciate if someone can give it to me, even the code up there, I found online.

    I know nothing about coding I'm gonna keep searching though but would love some help.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    As I said, it will be easier to find a new script that does what you want and use the same images in it. Adjusting this is possible, but it would require a strong understanding of the code and what needs to be done to change it.
    http://dynamicdrive.com/dynamicindex14/index.html
    That's a good place to start.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hey djr33! thanks so much! i was getting frustrated and that is probably why nothing seemed like it was working.

    i went ahead and figured out a code, but need slight help cuz i want to add a border.

    anyway!!! thanks so much!!!!

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    A border can probably be applied to an element surrounding the images: a div, in most cases. But if you need help with that, post a link to the page.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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

    Default

    modifying the original

    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">
    /*********Edit values here for your pictures*******************/
    var
    pic1='https://store-a32dc.mybigcommerce.com/product_images/uploaded_images/MOMSHOPPING2.gif',
    pic2='https://store-a32dc.mybigcommerce.com/product_images/uploaded_images/RRR.gif',
    pic3='https://store-a32dc.mybigcommerce.com/product_images/uploaded_images/2photos.jpg';
    /***************End of Edit*********************************/
    
    var rangPics=[pic1,pic2,pic3]; // Add all the picture variables in this array.
    
    window.onload=Test;
    
    function Test() {
     rangRandom=Math.floor(Math.random()*rangPics.length);
     if (this.nu==rangRandom){
      setTimeout('Test()',20);
      return;
     }
     document.getElementById('show').innerHTML='<img src="'+rangPics[rangRandom]+'" alt="myimage" style="width:950px;height:450px;">';
     setTimeout('Test()',2000);
     this.nu=rangRandom;
    }
    
    </script>
    <div id="show" style="text-align:center;width:950px;border:3px double #222;padding:10px;"></div>
    </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/

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That's a good solution.

    One note: that will not preload the images, so when they cycle the first time it will have to load them and if they are slow (slow server, slow user connection, big files, or other reason), then this will be disruptive. A full slideshow script could include this also.
    But in this case it may be best to keep this: usually simpler is better.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •