I have a working slideshow script that provides the following:
– Pulls images from image folder
– Renders caption text for each image
– Renders image count
– Contains Next and Previous image buttons with rollover effects
What I still need this script to do:
– Prevent slideshow from looping
– Disable the previous button when on the first image; disable the next button when on the last image
Coming from the Flash environment, my JavaScript web skills are lacking. Can someone give me a hand to resolve the stop the loop, show disabled button on first/last image issue?
thanks.
[CODE]
<script type=”text/javascript”>
<!–
function newImage(arg) {
if (document.images) {
rslt = new Image();
rslt.src = arg;
return rslt;
}
}
function changeImages() {
if (document.images && (preloadFlag == true)) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
}
}
}
var preloadFlag = false;
function preloadImages() {
if (document.images) {
demo_left_btn_01_over = newImage(“../images/demo_left_btn_01-over.gif”);
demo_left_btn_01_down = newImage(“../images/demo_left_btn_01-down.gif”);
demo_left_btn_01_disabled = newImage(“../images/demo_left_btn_01-disabled.gif”);
demo_rt_btn_01_over = newImage(“../images/demo_rt_btn_01-over.gif”);
demo_rt_btn_01_down = newImage(“../images/demo_rt_btn_01-down.gif”);
demo_rt_btn_01_disabled = newImage(“../images/demo_rt_btn_01-disabled.gif”);
preloadFlag = true;
}
}
function ShowState_disabled() {
changeImages(‘demo_left_btn_01’, ‘demo_left_btn_01_disabled’);
}
function ShowState_disabled() {
changeImages(‘demo_rt_btn_01’, ‘demo_rt_btn_01_disabled’);
}
// –>
</script>
<!– End Preload Script –>
<!– slideshow script –>
<script language=”JavaScript” type=”text/javascript”>
theimage = new Array();
// The dimensions of ALL the images should be the same or some of them may look stretched or reduced in Netscape 4.
// Format: theimage[…]=[image URL, link URL, name/description]
theimage[0]=[“../images/demo_imgs/image_01.gif”, “”, “Caption for image 01”];
theimage[1]=[“../images/demo_imgs/image_02.gif”, “”, “Caption for image 02”];
theimage[2]=[“../images/demo_imgs/image_03.gif”, “”, “Caption for image 03”];
theimage[3]=[“../images/demo_imgs/image_04.gif”, “”, “Caption for image 04”];
theimage[4]=[“../images/demo_imgs/image_05.gif”, “”, “Caption for image 05”];
///// Plugin variables
dotrans=0; // if value = 1 then there are transitions played in IE
//key that holds where in the array currently are
i=0;
//###########################################
window.onload=function(){
//preload images into browser
preloadSlide();
//set the first slide
SetSlide(0);
}
//###########################################
function SetSlide(num) {
//too big
i=num%theimage.length;
//too small
if(i<0)i=theimage.length-1;
//switch the image
if(document.all&&!window.opera&&dotrans==1)eval(‘document.images.imgslide.filters.’+transtype+’.Apply()’)
document.images.imgslide.src=theimage[i][0];
if(document.all&&!window.opera&&dotrans==1)eval(‘document.images.imgslide.filters.’+transtype+’.Play()’)
//if they want name of current slide
document.getElementById(‘captionbox’).innerHTML=theimage[i][2];
//if they want current slide number and total
document.getElementById(‘imagecount’).innerHTML= ” “+(i+1)+” / “+theimage.length;
}
//###########################################
function preloadSlide() {
for(k=0;k<theimage.length;k++) {
theimage[k][0]=new Image().src=theimage[k][0];
}
}
</script>