I'm taking a javascript class and my teacher gave me this script for fading images. However, he doesn't seem to know much about it himself so I'm left wondering about a few things. I hope someone won't mind have a look at my comments within the script to see where my issues (i mean, the stupid logic's issues) are. One set of comments at the beginning and the other more important set at the end. Thanks.
Oh yeah, any helpful links to a dictionary or some kind of glossary which will explain things like "filter", "filters", "style", "blendTrans", and "Image()", "Play()" and "Apply()"?
- Code: Select all
<script type="text/javascript">
var crossFadeDuration=3
//this variable is redundant because I can just input the number 3
//into the appropriate place further down the page, unless
//the author was trying to make a distinction between the two
//kinds of duration regarding blendTrans. Why is it listed twice?
var Pic = new Array();
Pic[0]="blah1.jpg";
Pic[1]="blah2.jpg";
Pic[2]="blah3.jpg";
Pic[3]="blah4.jpg";
Pic[4]="blah5.jpg;
var j = 0;
var preLoad = new Array();
for(i=0;i < pic.length;i++)
{
preLoad[i]= new Image();
preLoad[i].src = Pic[i]
}
function runSlideShow()
{
if(document.all)
{
document.images.SlideShow.style.filter="blendTrans(duration=2)";
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
document.images.SlideShow.filters.blendTrans.Apply();
}
document.images.SlideShow.src=preLoad[j].src;
if(document.all)
{
document.images.SlideShow.filters.blendTrans.Play();
}
j = j+1;
if(j>(pic.length-1)) j=0;
//this is the real subject of my confusion.[/b]
//I could also write this part as if(j < (pic.length-5)) j=0 and the script will still work.
//I can see that it is good for j=0 to be false. When j=0 is true, the script does not work.
//I can see that pic.length is the number of pics in the array, but why is it
//necessary for j=0 to be false? Why is this stupid j=0 important!
setTimeout("runSlideShow()",5000);
}
</script>


