Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 04-30-2008, 10:24 AM   #1 (permalink)
Registered User
 
Join Date: Aug 2007
Posts: 5
OS: Vista-Linux-XP sp2


rollover div to change image

Hi,

I am currently working on a site that I want to have multiple divs (the menu) that when you roll over them it would change the image in the page(each div having its own image). I've been trying to get this javascript to work but it dosn't look like its gona work because the onmouseover and onmouseout in the divs directs it to the image which can only have one name (or can it have more then one?). anyway can anybody help me with this? I don't know if I explained it properly but if you have questions then ask.



HTML Code:
if (document.images) { 
img1on = new Image();
img1on.src = "images/over1.jpg"; 
img1off = new Image(); 
img1off.src = "images/notover.jpg"; 
img2on = new Image();
img2on.src = "images/over2.jpg"; 
img2off = new Image(); 
img2off.src = "images/notover.jpg"; 
}
function imgOn(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "on.src");}
}
function imgOff(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "off.src");}
}

HTML Code:
<div><a href="" onmouseover="imgOn('img1')" onmouseout="imgOff('img1')">selection 1</a></div>
<div><a href="" onmouseover="imgOn('img2')" onmouseout="imgOff('img2')">selection 2</a></div>


<img name="img1" src="images/notover.jpg" alt="" />
xlrsound is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 05-01-2008, 04:30 PM   #2 (permalink)
Design Team Member
 
Jaxo's Avatar
 
Join Date: Feb 2008
Location: Deming, NM
Posts: 312
OS: XP SP2 & Vista


Question Re: rollover div to change image

Hey xlrsound,

Question for you. Are you trying to change an image located at the same spot your mouse hovers over? Like a button? OR... Are you trying to change and image located somewhere else on the page by hovering over a link/image in a different location? Make sense?

Just to help clear up my thinking. It would also help to have all code(all css and html) and a link to the site if possible.

Thanks.
Jaxo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-01-2008, 07:27 PM   #3 (permalink)
Registered User
 
Join Date: Aug 2007
Posts: 5
OS: Vista-Linux-XP sp2


Re: rollover div to change image

Quote:
Originally Posted by Jaxo View Post
Hey xlrsound,

Question for you. Are you trying to change an image located at the same spot your mouse hovers over? Like a button? OR... Are you trying to change and image located somewhere else on the page by hovering over a link/image in a different location? Make sense?

Just to help clear up my thinking. It would also help to have all code(all css and html) and a link to the site if possible.

Thanks.
I am trying to change and image located somewhere else on the page by hovering over a div. The site is in the early stages so I don't have it on a server yet, but here is the whole page so far.

HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>

<link rel="stylesheet" type="text/css" href="style.css" />
<script language="javascript" src="menu_mouseover.js"></script> 


</head>
<body>

<center>
<table border="0" cellpadding="5" cellspacing="0"><tr>

<td align="center">
 <img src="images/head.jpg" alt=""/>
  </td>
	
	<td width="300" align="center" valign="top" class="******">
	 ********<br />***********
	  </td>
		
	<tr><td colspan="2" align="center"><font color="#616568">
	  <a href="" class="top">******</a>
	 &nbsp;&nbsp;|&nbsp;&nbsp;
		 <a href="" class="top">********</a>
		&nbsp;&nbsp;|&nbsp;&nbsp;
		  <a href="" class="top">******</a>
	
	</td></tr></font>

</tr></table>


<table border="0" cellpadding="10" cellspacing="0"><tr><td colspan="2" valign="top">
<img src="images/cat_bg.jpg" alt="" />
<div><a class="menu" href="" onmouseover="imgOn('img1')" onmouseout="imgOff('img1')">selection</a></div>
<div><a class="menu" href="" onmouseover="imgOn('img2')" onmouseout="imgOff('img2')">selection</a></div>
<div><a class="menu" href="">selection</a></div>
<div><a class="menu" href="">selection</a></div>
<div><a class="menu" href="">selection</a></div>
<div><a class="menu" href="">selection</a></div>

<br />

<img src="images/cat_bg.jpg" alt="" />
<div><a class="menu" href="">selection</a></div>
<div><a class="menu" href="">selection</a></div>
<div><a class="menu" href="">selection</a></div>
<div><a class="menu" href="">selection</a></div>
<div><a class="menu" href="">selection</a></div>
<div><a class="menu" href="">selection</a></div>
</td>


<td width="620" valign="top"><img src="images/tl.jpg" /><img width="570" height="25" src="images/t.jpg" /><img src="images/tr.jpg" /><table border="0" cellpadding="20" cellspacing="0" width="620" bgcolor="white"><tr><td><img name="img1" src="images/notover.jpg" alt="" /><br/>**** ******* ************* ********************* ****** ** ************************ **** ******** ********** ****** ******* **** *** ****** ***</td></tr></table></td>




</tr></table>

</center>



</body>
</html>
Here is the menu_mouseover.js file
Code:
if (document.images) { 
img1on = new Image();
img1on.src = "images/over1.jpg"; 
img1off = new Image(); 
img1off.src = "images/notover.jpg"; 
img2on = new Image();
img2on.src = "images/over2.jpg"; 
img2off = new Image(); 
img2off.src = "images/notover.jpg"; 
}
function imgOn(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "on.src");}
}
function imgOff(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "off.src");}
}
xlrsound is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-08-2009, 09:27 AM   #4 (permalink)
Registered User
 
Join Date: May 2009
Posts: 2
OS: XP


Re: rollover div to change image

Hi - this is something I am trying to do too -- I have a product gallery with a menu on the left side -- when you mouse over a menu item, I'd like the image in the main section of the gallery page change to an image related to that menu item --

I would appreciate any recommendations on css tricks to research and try --

I suppose you could do the whole thing in flash....
Tedrick is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-08-2009, 09:28 AM   #5 (permalink)
Registered User
 
Join Date: May 2009
Posts: 2
OS: XP


Re: rollover div to change image

re: java scripting -- I'm afraid most people are beginning to disable java scripting -- so this might not be a good route --
Tedrick is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-08-2009, 01:08 PM   #6 (permalink)
God (TSF Enthusiast)
 
ahmorrow's Avatar
 
Join Date: May 2009
Location: Jeffersonville, IN
Posts: 903
OS: Ubuntu 9.10 [Karmic Koala]

My System

Send a message via AIM to ahmorrow Send a message via Yahoo to ahmorrow
Re: rollover div to change image

Tedrick did you mean Java--scripting or JavaScript scripting? There's a bit of a difference.
__________________
If I have not responded to a post in 24 hours or more, PM me with a link to the thread and I'll get back to you. I do not help via PM/IM/Email.
ahmorrow is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-08-2009, 01:34 PM   #7 (permalink)
Registered User
 
FredT's Avatar
 
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2


Re: rollover div to change image

What is wrong here? I tested it and it worked for me. Only the first rollover worked, though, because there is no image in the document called 'img2'.

Edit - Could you clarify this?
Quote:
it dosn't look like its gona work because the onmouseover and onmouseout in the divs directs it to the image which can only have one name

Last edited by FredT; 05-08-2009 at 01:35 PM.
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-10-2009, 01:14 PM   #8 (permalink)
Registered User
 
Join Date: May 2007
Location: British Columbia, Canada
Posts: 53
OS: vista


Re: rollover div to change image

Take a look a this code...I haven't tested it but it should give you the idea:

Code:
<script type="text/javascript">
  
function imgOn(imgNumber) **
    if (document.images)
    document.getElementById("Image" + imgNumber.toString()).src = "images/over" + imgNumber.toString() + ".jpg";
}

function imgOff(imgNumber) **
    if (document.images)
    document.getElementById("Image" + imgNumber.toString()).src = "images/notover.jpg";
}

</script>


Code:
<body>

<div>
  <img id="Image1" src="images/notover.jpg" alt="" onmouseover="imgOn(1)" onmouseout="imgOff(1)"/>
</div>

<div>
  <img id="Image2" src="images/notover.jpg" alt="" onmouseover="imgOn(2)" onmouseout="imgOff(2)"/>
</div>


  </body>
BrentC is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 07:32 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85