1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript slideshow help

Discussion in 'JavaScript' started by piri00, Mar 28, 2010.

  1. #1
    Hi I did some code for slide show. It works fine just I wish to add this slide show few times on one website with different images.
    I mean if I want to use 5 different slide shows I need to repeat this code 5 times
    Is there any chance that I don't need to repeat this code in JavaScript external files and change arrays for each new slide show what i want to use?
    I wish somehow change just arrays with different images which depend on what slide show is clicked on... if that is possible?

    thank you for any help


    myImages=new Array();
    myImages[0]="images/opt.images/energyshots/optDr_dunkel_logo.jpg";
    myImages[1]="images/opt.images/energyshots/optDr_hell.jpg";
    myImages[2]="images/opt.images/energyshots/opt92__news_gross.jpg";
    myImages[3]="images/opt.images/energyshots/opt91__news_gross.jpg";
    myImages[4]="images/opt.images/energyshots/opt93__news_gross.jpg";
    //imagecounter=myImages.length-1;
    i=0;
    
    function previous(){
    if (i == 0) {
    		i = myImages.length;
    	}
    	i--;
    	document.getElementById('imageviewer').src=myImages[i];
    	}
    
    
    function next()
     {
    	i++;
    	if (i == myImages.length) {
    		i = 0;
    	}
    	document.getElementById('imageviewer').src=myImages[i];
    	}
    
    function canceltime() {
    	clearTimeout(the_timeout); 
    }
    
    function changeImage()
    
    {
        document.getElementById('imageviewer').src=myImages[i];
        i++;
        if (i >= myImages.length) 
        {
            i = 0;
        }
         the_timeout = setTimeout("changeImage();", 1000);
    }
    
    
    
    Code (markup):

     
    piri00, Mar 28, 2010 IP