mikerawlins
Technical User
Following the guide here:
I've got a series of photos rotating in sequence every few seconds. I've got one file called banner.js.js with the code shown at bottom of this post. In my main index.html file I have the few lines immediately below. It works, but perhaps it's not done right. How do I place a caption that changes for each photo? Most of the code I've seen to do this seems MUCH more complicated. Thanks!
<p><div align="center">
<!-- <img src="image_jss.gif" name="banner"> -->
<img src="photo_JBG_0315.JPG" name="banner" width="400" height="267">
<div class="slideTitle"> CAPTION TEXT
</div>
</div><p>
<!-- Paste this code into an external JavaScript file named: banner.js.js -->
/* This script and many more are available free online at
The JavaScript Source :: Created by: Lee Underwood :: */
var bannerImg = new Array();
// Enter the names of the images below
bannerImg[0]="photo_JBG_0315.JPG";
bannerImg[1]="photo_JBG_3341.JPG";
bannerImg[2]="photo_JBG_3506.JPG";
var newBanner = 0;
var totalBan = bannerImg.length;
function cycleBan() {
newBanner++;
if (newBanner == totalBan) {
newBanner = 0;
}
document.banner.src=bannerImg[newBanner];
// set the time below for length of image display
// i.e., "4*1000" is 4 seconds
setTimeout("cycleBan()", 8*1000);
}
window.onload=cycleBan;
I've got a series of photos rotating in sequence every few seconds. I've got one file called banner.js.js with the code shown at bottom of this post. In my main index.html file I have the few lines immediately below. It works, but perhaps it's not done right. How do I place a caption that changes for each photo? Most of the code I've seen to do this seems MUCH more complicated. Thanks!
<p><div align="center">
<!-- <img src="image_jss.gif" name="banner"> -->
<img src="photo_JBG_0315.JPG" name="banner" width="400" height="267">
<div class="slideTitle"> CAPTION TEXT
</div>
</div><p>
<!-- Paste this code into an external JavaScript file named: banner.js.js -->
/* This script and many more are available free online at
The JavaScript Source :: Created by: Lee Underwood :: */
var bannerImg = new Array();
// Enter the names of the images below
bannerImg[0]="photo_JBG_0315.JPG";
bannerImg[1]="photo_JBG_3341.JPG";
bannerImg[2]="photo_JBG_3506.JPG";
var newBanner = 0;
var totalBan = bannerImg.length;
function cycleBan() {
newBanner++;
if (newBanner == totalBan) {
newBanner = 0;
}
document.banner.src=bannerImg[newBanner];
// set the time below for length of image display
// i.e., "4*1000" is 4 seconds
setTimeout("cycleBan()", 8*1000);
}
window.onload=cycleBan;