Saturday, March 30, 2013

Images Slide show - Image array in Java script

#Code to make images as slide show by using images in an array

<!-- script for reading the images from the image array for slideshow.  -->

<script language="JavaScript" type="text/javascript">
<!--
var imgArray=  new Array( "images/eg1.jpg",  "images/eg2.jpg ");

var rotate_delay = 5000;// delay in milliseconds (5000 = 5 secs)

current = 0;


function next() {
if (document.slideform.slide.value<imgArray.length-1) {
document.images.show.src = imgArray[current+1];
document.slideform.slide.value = ++current;
}
else first();
}

function previous() {
if (current-1 >= 0) {
document.images.show.src = imgArray[current-1];
document.slideform.slide.value = --current;
}
else last();
}

function first() {
current = 0;
document.images.show.src = imgArray[0];
document.slideform.slide.value = 0;
}

function last() {
current = imgArray.length-1;
document.images.show.src = imgArray[current];
document.slideform.slide.value = current;
}

function ap(text) {
document.slideform.slidebutton.value = (text == "Stop") ? "Start" : "Stop";
rotate();
}


function rotate() {
if (document.slideform.slidebutton.value == "Stop") {
current = (current == imgArray.length-1) ? 0 : current+1;
document.images.show.src = imgArray[current];
document.slideform.slide.value = current;
window.setTimeout("rotate()", rotate_delay);
}
}

//-->
</script>

No comments:

Post a Comment