Simple JavaScript/HTML Slideshow

TopChef picture TopChef · Sep 27, 2011 · Viewed 74.4k times · Source

New to Javascript, but after some research it loks like this would be the best method in implementing my desired output. I'm trying to produce a slideshow of images (5 pre-selected images) that automatically change between 5 second intervals. Can anyone point towards a tutorial or guide me along in this process? Any help is very much appreciated.

Answer

shuseel picture shuseel · Jan 16, 2014

Here is a Very simple code to create simple JavaScript/HTML slideshow only by using simple JavaScript and HTML codes :

<script language="JavaScript"> 
var i = 0; var path = new Array(); 

// LIST OF IMAGES 
path[0] = "image_1.gif"; 
path[1] = "image_2.gif"; 
path[2] = "image_3.gif"; 

function swapImage() 
{ 
document.slide.src = path[i]; 
if(i < path.length - 1) i++; 
else i = 0; 
setTimeout("swapImage()",3000); 
} 
window.onload=swapImage; 
</script> 
<img height="200" name="slide" src="image_1.gif" width="400" />