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

rollover image

Status
Not open for further replies.

krichard

Technical User
Dec 5, 2001
41
US
Hello...

i have some code below that was created using Dreamweaver. Basically when i rollover an image it changes that image to a new one that is the same size, but what i would like to have happen is have to new image swap to be a BIGGER different picture... not the same size as the original... is this possible and how???

THANKS KIM :)

<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a.indexOf(&quot;#&quot;)!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf(&quot;?&quot;))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>

<a href=&quot;C.htm&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Image24','','Images/bannerbaby.jpg',1)&quot;><img src=&quot;Images/Instrumentation/recorder.jpg&quot; name=&quot;Image24&quot; width=&quot;50&quot; height=&quot;50&quot; border=&quot;1&quot;></a>
 
I think the easiest solution would be to omit the height and width attributes in the original image code.

Otherwise I have written the following code and it seems to work OK ( I have left out the onmouseout event tho:

<script>
function rollme() {
myImg=new Image();
myImg.src=&quot;006840.thb.jpg&quot;;
y = myImg.width // the img width
x = myImg.height; //the img height

document.images[0].width = y;
document.images[0].height = x;
document.images[0].src = &quot;006840.thb.jpg&quot;;
}
</script>
<img name=&quot;blah&quot; id=&quot;blah&quot; src=&quot;5241_030614_10600.jpg&quot; height=&quot;131&quot; width=&quot;180&quot; onmouseover=&quot;rollme()&quot;>

Nigel Wilson
&quot;kiwi-kid&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top