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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image rollover script

Status
Not open for further replies.

Izzo

Technical User
Feb 22, 2001
38
US
Hi All,
I'm trying to make an image rollover script work by using the "same" functions (Iswap) and (Iback) for 2 different variables(?) ovr,nrm and ovrB,nrmB.

The script below works for the first set-(ovr,nrm) but I need to know how to make it work for the second set-(ovrB,nrmB)as well.

How do I add these in to the Iswap and Iback functions to make them both work?

Thanks...






function PreloadImages(length, path, type) {
for(var i = 1; i<=length; i++) {
this= new Image()
this.src= path + i + type
}
return this
}
ovr=new PreloadImages(10,'images/sub1butovr','.gif')
nrm=new PreloadImages(10,'images/sub1but','.gif')
ovrB=new PreloadImages(10,'images/sub2butovr','.gif')
nrmB=new PreloadImages(10,'images/sub2but','.gif')
function Iswap(no){

if (document.images){
eval('document.images[&quot;nrm'+no+'&quot;].src ='+'ovr[no].src')
}
}
function Iback(no){

if (document.images){
eval('document.images[&quot;nrm'+no+'&quot;].src ='+'nrm[no].src')
}
}
 
I dont rly understand your question, but you could try adding another variable when you call the function and then do a test to see what rollover it should do.... -Greg :-Q
 
Hi Greg,

Basically I want the same functions (Iswap,Iback) to rollover 2 sets of differently named images.

The script works to rollover the first set named &quot;sub1but,sub1butovr&quot; but I don't know how to reference the other set sub2but,sub2ovr&quot; without creating 2 more functions like (Iswap2,Iback2)

Dave

 
Then I dont see the problem, you want 2 rollovers to happen at the same time, right? Just put the code for the other rollover in the function. Or am I still not understanding this right -Greg :-Q
 
I'm pretty sure I know what you're talking about Izzo & I have just the script.

Put this in the head, & modify it as you need.
<script><!--
var g_images = new Array();
g_images[0] = new Image();
g_images[0].src = &quot;News1.gif&quot;;
g_images[1] = new Image();
g_images[1].src = &quot;News2.gif&quot;;
g_images[2] = new Image();
g_images[2].src = &quot;Staff1.gif&quot;;
g_images[3] = new Image();
g_images[3].src = &quot;Staff2.gif&quot;;
g_images[4] = new Image();
g_images[4].src = &quot;Links1.gif&quot;;
g_images[5] = new Image();
g_images[5].src = &quot;Links2.gif&quot;;
g_images[6] = new Image();
g_images[6].src = &quot;Home1.gif&quot;;
g_images[7] = new Image();
g_images[7].src = &quot;Home2.gif&quot;;
function imgRotate(nIndex, obj){
if ( g_images[0].complete)
obj.src = g_images[nIndex].src;}
function imgRotate2(nIndex, obj){
if ( g_images[2].complete)
obj.src = g_images[nIndex].src;}
function imgRotate3(nIndex, obj){
if ( g_images[4].complete)
obj.src = g_images[nIndex].src;}
function imgRotate4(nIndex, obj){
if ( g_images[6].complete)
obj.src = g_images[nIndex].src;}
//-->
</script>


Put this in the body & modify as necessary.

<a href=&quot;#&quot; onMouseDown=&quot;javascript:imgRotate(1, News)&quot; onMouseUp=&quot;javascript:imgRotate(0, News)&quot;>
<img src=&quot;News1.gif&quot; name=&quot;News&quot; height=&quot;50&quot; width=&quot;200&quot; border=&quot;0&quot;/></a>

I hope that this helps. If you need help sorting it out, let me know. My e-mail is ID10T16@aol.com
 
Greg, yeah I know it's confusing to understand what I'm after. I don't want the images to swap at the same time.

Imagine 20 images on a page. Using the script above I could swap them all (1 by 1) with the (Iswap) function as long as they are named the same.
nrm1
nrm2
nrm3
nrm4 etc...all the way to nrm20

but

I would like to divide this group of 20 into 2 groups of 10 so that each group can start the naming process at &quot;1&quot;

nrm1
nrm2
nrm3 etc... all the way to nrm10

then the 2nd group would be:
nrmB1
nrmB2
nrmB3 etc...all the way to nrmB10

then be able to swap from either group with the same (Iswap) function.
The problem is getting the script to recognize that there are 2 sets of images on the page and they both are sequentially numbered 1 thru 10 and to be able to use the &quot;same&quot; function for both sets.

Dave
 
Hey Idiot16,

I'm still chewing on your script to see if it will work. I looks like it would be pretty lenghty tho. I was hoping to preload the whole shabang. I will post back if it does work tho.
thanks for yours and Gregs time

Izzo
 
hie Izzo
try 2 pass some flag into ur Iswap
function Iswap(no,flag){
if (document.images){
if (flag) eval('document.images[&quot;nrm'+no+'&quot;].src ='+'ovr[no].src')
else eval('document.images[&quot;nrmB'+no+'&quot;].src ='+'ovrB[no].src')}
}

regards, vic
 
ok now I get it, you just have to pass the variable names when you call the function sort of like vituz said but somethin like:

Code:
onMouseover=&quot;Iswap(nrm1, nrmB1)&quot;

then call the function like this:

function Iswap(img1, img2) 

and then just use img1 and img2 as your variables

-Greg :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top