Current location: Hot Scripts Forums » General Web Coding » JavaScript » Image Swap on a text link Roll Over


Image Swap on a text link Roll Over

Reply
  #1 (permalink)  
Old 04-14-04, 01:40 AM
Jaali's Avatar
Jaali Jaali is offline
New Member
 
Join Date: Apr 2004
Location: Tasmania, Australia
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Image Swap on a text link Roll Over

Hi All,

I am wanting to get a script that will enable me to have an image on the page change when I roll my mouse over a text link elsewhere on the page.

It needs to default back to the original image once you rolloff the text link. There are five text links. I need it to change the one picture to five different ones, depending on which link I roll-over, if you know what i mean.

Thanks heaps for all your help!

Cheers,

Jaali
Reply With Quote
  #2 (permalink)  
Old 04-15-04, 09:43 AM
dcooldude_1's Avatar
dcooldude_1 dcooldude_1 is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Sidney
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
I know exactly what you mean. I had to do a project for this a while back in class.

What you have to do is set an array. Well, never mind. I'll just write one for you.This will be in javascript. So put the < script > tags around it.


Code:
changeIMG = new Array(6);
changeIMG[0] = new Image;
changeIMG[0].src = "http://www.somewhere.com/mainimage.extension";
changeIMG[1] = new Image;
changeIMG[1].src = "http://www.somewhere.com/image1.extension";
changeIMG[2] = new Image;
changeIMG[2].src = "http://www.somewhere.com/image2.extension";
changeIMG[3] = new Image;
changeIMG[3].src = "http://www.somewhere.com/image3.extension";
changeIMG[4] = new Image;
changeIMG[4].src = "http://www.somewhere.com/image4.extension";
changeIMG[5] = new Image;
changeIMG[5].src = "http://www.somewhere.com/image5.extension";

function doChangeMe(whichone)
{
document.myIMG.src=changeIMG[whichone].src;
}

//Close script here

<img src="http://www.somewhere.com/mainimage.extension" name="myIMG">

<a href="" onMouseOver="doChangeMe('1')" onMouseOut="doChangeMe('0')">Change to image 1</a>

<a href="" onMouseOver="doChangeMe('2')" onMouseOut="doChangeMe('0')">Change to image 2</a>

<a href="" onMouseOver="doChangeMe('3')" onMouseOut="doChangeMe('0')">Change to image 3</a>

<a href="" onMouseOver="doChangeMe('4')" onMouseOut="doChangeMe('0')">Change to image 4</a>

<a href="" onMouseOver="doChangeMe('5')" onMouseOut="doChangeMe('0')">Change to image 5</a>
To quickly explain this, the top part is an array. Change only the red parts. Don't change the 6 unless you have too. That number HAS to be one more then the last array you have. So, if you have changeIMG[6] the 6 in the new Array part HAS to be 7. The reason for that is javascript starts at 0.

The blue url's should be the same. This is the main image that will be seen first, and when you mouse out. Take this code and run with it. Let me know if it doesn't work.
__________________
===================================
Dcooldude_1

Site 1: http://ih.sidneyps.com/hs/spokesman/
Site 2: http://www.webhex.net/

Go to http://www.chatzy.com/?132627185966 this is my chat area...
the password is: progtalk
===================================
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Text Link Swap ibanners Traffic Exchange 2 08-20-04 03:29 PM
MySQL Query problem Wraith PHP 5 03-06-04 05:16 PM
how to change text dynamically with image? rabbit51 JavaScript 1 02-23-04 08:35 AM
How to change text dynamically with image? rabbit51 Script Requests 0 02-07-04 12:14 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM


All times are GMT -5. The time now is 02:15 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.