Problem with first slide image link

Discussion in 'JavaScript' started by caligrafx, Jan 4, 2011.

  1. #1
    I have this javascript in my website that works great but there is something buggy about the first loaded image... on refresh the first images link is referring to the second slide, but if you let it run or go back to the first image the link is fine!

    Just though someone might be able to help me out with this!

    Thanks,
    Adam

    http://www.totallymotorsports.com/

    Here is the javascript if you would like to look at it!

    <script type="text/javascript">var Pix=new Array("http://ep.yimg.com/ca/I/yhst-79301798698892_2140_155091121","http://ep.yimg.com/ca/I/yhst-79301798698892_2138_364267695","http://ep.yimg.com/ca/I/yhst-79301798698892_2138_364496823","http://ep.yimg.com/ca/I/yhst-79301798698892_2138_364693919"); var timeDelay=4;var howMany = Pix.length;
    timeDelay *= 1000;
    var PicCurrentNum = 0;
    var PicCurrent = new Image();
    
    var intervalId = 0;
    PicCurrent.src = Pix[PicCurrentNum];
    
    function startPix() {
    intervalId=setInterval("slideshow()", timeDelay);
    }
    function slideshow() {
    PicCurrentNum++;
    if (PicCurrentNum == howMany) {
    PicCurrentNum = 0;
    }
    PicCurrent.src = Pix[PicCurrentNum];
    document["ChangingPix"].src = PicCurrent.src;
    document['ChangingPix'].useMap= '#rotatemap' + PicCurrentNum;
    //z=document.getElementById('Rotate-Link');
    //z.href=Linkz[PicCurrentNum];
    }
    
    
    
    function changeSlide(num) { 
    PicCurrentNum=num; 
    PicCurrent.src = Pix[num]; 
    document['ChangingPix'].src = PicCurrent.src; 
    document['ChangingPix'].alt = PicCurrent.alt;
    document['ChangingPix'].useMap= '#rotatemap' + num;
    clearInterval(intervalId); 
    intervalId=setInterval('slideshow()', timeDelay);
    }
    
    startPix();</script>
    Code (markup):

     
    caligrafx, Jan 4, 2011 IP
  2. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #2
    Just need to move on line:
    PicCurrentNum++;
    you had it incrementing before setting the first item see where I put it below:


    
    <script type="text/javascript">var Pix=new Array("http://ep.yimg.com/ca/I/yhst-79301798698892_2140_155091121","http://ep.yimg.com/ca/I/yhst-79301798698892_2138_364267695","http://ep.yimg.com/ca/I/yhst-79301798698892_2138_364496823","http://ep.yimg.com/ca/I/yhst-79301798698892_2138_364693919"); var timeDelay=4;var howMany = Pix.length;
    timeDelay *= 1000;
    var PicCurrentNum = 0;
    var PicCurrent = new Image();
    
    var intervalId = 0;
    PicCurrent.src = Pix[PicCurrentNum];
    
    function startPix() {
    intervalId=setInterval("slideshow()", timeDelay);
    }
    function slideshow() {
    
    if (PicCurrentNum == howMany) {
    PicCurrentNum = 0;
    }
    PicCurrent.src = Pix[PicCurrentNum];
    document["ChangingPix"].src = PicCurrent.src;
    document['ChangingPix'].useMap= '#rotatemap' + PicCurrentNum;
    //z=document.getElementById('Rotate-Link');
    //z.href=Linkz[PicCurrentNum];
    PicCurrentNum++;
    }
    
    
    
    function changeSlide(num) { 
    PicCurrentNum=num; 
    PicCurrent.src = Pix[num]; 
    document['ChangingPix'].src = PicCurrent.src; 
    document['ChangingPix'].alt = PicCurrent.alt;
    document['ChangingPix'].useMap= '#rotatemap' + num;
    clearInterval(intervalId); 
    intervalId=setInterval('slideshow()', timeDelay);
    }
    
    startPix();</script>
    
    Code (markup):
     
    shofstetter, Jan 7, 2011 IP
  3. caligrafx

    caligrafx Active Member

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #3
    Sweet thanks!
     
    caligrafx, Jan 10, 2011 IP