Web Programming Training By OM SIR Call for free Demo :9320957717/18

simple slideshow code in javascript

<script type="text/javascript">
var i = 0;
var image = new Array();  
// LIST OF IMAGES
image[0] = "php_img.png";
image[1] = "domain.jpg";
image[2] = "1.png";  
image[3]="2.jpg";
var k = image.length-1;  

var caption = new Array();

// LIST OF CAPTİONS
caption[0] = "Caption for the first image";
caption[1] = "Caption for the second image";
caption[2] = "Caption for the third image";  

function swapImage(){
var el = document.getElementById("mydiv");
el.innerHTML=caption[i];
var img= document.getElementById("slide");
img.src= image[i];
if(i < k ) { i++;}
else  { i = 0; }
setTimeout("swapImage()",5000);
}

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
}
else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();}}}
addLoadEvent(function() {
swapImage(); });
</script>

<table style="border:3px solid #00aaff;background-color:#00aaaa;">
<tr>
<td>
<img name="slide" id="slide" alt ="my images" height="285" width="485" src="php_img.png"/>
</td>

</tr>
<tr>
<td align="center"style="font:small-caps bold 15px georgia; color:blue;">
<div id ="mydiv"></div>
</tr>
</td>
</table> 
Previous
Next Post »