SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript slide show

    i got this code from cnet to create a slideshow with javascript, is it possible to modify this code that when it reaches the last slide, instead of starting the show over, it moves on to another page??
    The code in action can be viewed here:
    http://builder.cnet.com/webbuilding/...upid/ss07.html Thanks in advance for any help


    PHP Code:
    <script language="JavaScript1.2">
    <!--
    // Cross-browser cleanup by Paul Anderson, CNET Builder.com. All rights reserved.
    var numSlides 5;
    var 
    currentSlide numSlides;
    // remove the next six lines if you don't want captions:
    var captionTxt = new Array(numSlides);
    captionTxt[1] = "Entrance to Pier 39"
    captionTxt[2] = "Sea lions lounging around the pier"
    captionTxt[3] = "Boats docked on the pier"
    captionTxt[4] = "Underwater World whale mural"
    captionTxt[5] = "Alcatraz, or The Rock"

    function setUp() {
    if (!
    document.all) {
       
    document.all document;
       for (
    i=1;i<=numSlides;i++) document.all[("image"+i)].style=document.all[("image"+i)];
       }
    switchSlide(1);
    }

    function 
    switchSlide(sDir) {
    newSlide currentSlide sDir;
    if (!
    newSlidenewSlide=numSlides;
    if (
    newSlide numSlidesnewSlide=1;
    document.all[("image"+newSlide)].style.visibility="visible";
    document.all[("image"+currentSlide)].style.visibility="hidden";
    // remove the next line if you don't want captions:
    document.all["captions"].document.forCaptions.captionsText.value=captionTxt[newSlide];
    currentSlide newSlide;
    }

    //-->
    </script> 

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing this line: if (newSlide > numSlides) newSlide=1;

    To this:
    if (newSlide > numSlides) location.href="somepage.html";

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well that did get rid of the error, however, as soon as the slide show page loads, it redirects it to the new page already skipping the slide show. I appreciate your help though.

  4. #4
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay - I should have looked at the script a little closer. The reason it is redirecting as soon as the page loads is because of these two lines:
    var numSlides = 5;
    var currentSlide = numSlides;

    The variable currenSlide is being set to the last entry in the array so that when you perform the function switchSlide() from the function setUp() it passes the number one (1) to it which is added to currentSlide to start the slideshow at the first entry. Try setting the variable currentSlide to zero and see if that works.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah i realized that too at the same time...thanks alot for your help.........


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
  •