Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple independent slideshows within a single page

Status
Not open for further replies.

diplotek

Technical User
Jul 3, 2003
2
US
Would someone tell me how to modify the script below to accomodate several instances of it within a single page?
Thanks!
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
src = [&quot;1.jpg&quot;, &quot;2.jpg&quot;, &quot;3.jpg&quot;]
duration = 5;
ads=[]; ct=0;
function switchAd() {
var n=(ct+1)%src.length;
if (ads[n] && (ads[n].complete || ads[n].complete==null)) {
document[&quot;Ad_Image&quot;].src = ads[ct=n].src;
}
ads[n=(ct+1)%src.length] = new Image;
ads[n].src = src[n];
setTimeout(&quot;switchAd()&quot;,duration*1000);
}
function doLink(){
location.href = url[ct];
} {
if (document.images)
switchAd();
}
</SCRIPT>
 
The easiest way would simply be to copy and paste it, changing all the variable and function names:
[tt]
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
src_1 = [&quot;1.jpg&quot;, &quot;2.jpg&quot;, &quot;3.jpg&quot;]
duration_1 = 5;
ads_1=[]; ct_1=0;
function switchAd_1() {
var n_1=(ct_1+1)%src_1.length;
...
...
...
[/tt]
 
I must be missing something. When I just change &quot;src&quot; to &quot;src_1&quot; throughout the script, it doesn't work at all. I tested it all by itself in a blank document too. Are some &quot;src&quot; references variables and others not?

Thanks in advance for your help!
 
Ja, hehe... src is also a property name of some html elements. ie
[tt]
document[&quot;Ad_Image&quot;].src = ads[ct=n].src;
[/tt]
both of these 'src' refer to the source url of an image object.

Remove the '_1' off any src that is preceded by a '.' and you should be on the right track. I take it you didn't write the original script, but whoever did needs a gentle smack in the ear for using a property name as a variable.
 
Can someone tell me how to modify this code to do the same thing? I've tried copying it four times and changing the chgSlide to chgSlide2, 3, and 4, but when I try to move the code that creates the four different myPix arrays into each function the slides all stop at slide #2. Even though there should be 4 in the array. Hope that makes sense.

<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
myPix = new Array("picture1.gif","picture2.gif","picture3.gif","picture4.gif")
thisPic = 0
imgCt = myPix.length - 1

function chgSlide(direction) {
if (document.images) {
thisPic = thisPic + direction
if (thisPic > imgCt) {
thisPic = 0
}
if (thisPic < 0) {
thisPic = imgCt
}
document.myPicture.src=myPix[thisPic]
}
}
</SCRIPT>

Thanks!

~ lahddah
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top