Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,583 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,935 people online right now. Registration is fast and FREE... Join Now!




Help on Hover-Over image change.

3 Pages V  1 2 3 >  
Reply to this topicStart new topic

Help on Hover-Over image change.

DeceitfulPillow
27 Sep, 2008 - 09:24 PM
Post #1

New D.I.C Head
*

Joined: 22 Jun, 2008
Posts: 26



Thanked: 1 times
My Contributions
Alright, basically, in my navigation bar I have an image than I need to change to another image when you hover over it and the link. Well for some reason my code isn't working. Can someone help?

CODE
<a href="/home"><img src="image1.gif"
onmouseover="img src='image2.gif'"
onmouseout="img src='image1.gif'" />Home</a>

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Help On Hover-Over Image Change.
27 Sep, 2008 - 09:53 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,213



Thanked: 217 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Simply change it to this...

CODE

<a href="/home"><img src="image1.gif"
onmouseover="this.src='image2.gif'"
onmouseout="this.src='image1.gif'" />Home</a>


This tells it to change the src property of "this" object. "This" should fix your problem... play on words intended. wink2.gif

Good luck!
User is offlineProfile CardPM
+Quote Post

DeceitfulPillow
RE: Help On Hover-Over Image Change.
27 Sep, 2008 - 09:57 PM
Post #3

New D.I.C Head
*

Joined: 22 Jun, 2008
Posts: 26



Thanked: 1 times
My Contributions
Thank you, but is there a way to have it change, when I hover over the text as well?

Edit: There also seems to be a blue border around the image due to it being a link. How can I remove this?

This post has been edited by DeceitfulPillow: 27 Sep, 2008 - 09:59 PM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Help On Hover-Over Image Change.
27 Sep, 2008 - 10:08 PM
Post #4

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,213



Thanked: 217 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Get rid of the border by setting the property "border" equal to 0 in the image....

CODE

<a href="/home"><img src="image1.gif"
onmouseover="this.src='image2.gif'"
onmouseout="this.src='image1.gif'" border="0"/>Home</a>


As for the text to also change the image is going to take a bit more work since it is not the image itself. You can instead move the onmouseover and onmouseout to the <a> tag instead and give the picture a "UNIQUE" name in the form of an id.

CODE

<a href="/home" onmouseover="homepic.src='image2.gif'"
onmouseout="homepic.src='image1.gif'"><img src="image1.gif" border="0" id="homepic"/>Home</a>


Hope that works out for you. smile.gif

User is offlineProfile CardPM
+Quote Post

DeceitfulPillow
RE: Help On Hover-Over Image Change.
27 Sep, 2008 - 10:13 PM
Post #5

New D.I.C Head
*

Joined: 22 Jun, 2008
Posts: 26



Thanked: 1 times
My Contributions
Sorry again but this time the image doesn't even show up. sad.gif


EDIT: NVM you're a genius It works. THank you wink2.gif

This post has been edited by DeceitfulPillow: 27 Sep, 2008 - 10:15 PM
User is offlineProfile CardPM
+Quote Post

DeceitfulPillow
RE: Help On Hover-Over Image Change.
27 Sep, 2008 - 10:23 PM
Post #6

New D.I.C Head
*

Joined: 22 Jun, 2008
Posts: 26



Thanked: 1 times
My Contributions
Spoke too soon. Now, I'm not sure if there is a way to fix this but when you hover over the link, the image change works but the mouse and link start to spasm.
User is offlineProfile CardPM
+Quote Post

webmin
RE: Help On Hover-Over Image Change.
28 Sep, 2008 - 07:11 AM
Post #7

D.I.C Head
**

Joined: 21 May, 2008
Posts: 96


My Contributions
I like this concept, but I don't want to change the image I'm using, I just want to change the width and height onmouseover. Can I do this?

Thanks
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Help On Hover-Over Image Change.
28 Sep, 2008 - 07:26 AM
Post #8

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,026



Thanked: 82 times
Dream Kudos: 1175
My Contributions
Yes, just use the different properties.

@Pillow - What browser are you using, it (Martyr's code) works fine in IE 7. I haven't tested on other browser ATP though.
User is offlineProfile CardPM
+Quote Post

webmin
RE: Help On Hover-Over Image Change.
28 Sep, 2008 - 07:34 AM
Post #9

D.I.C Head
**

Joined: 21 May, 2008
Posts: 96


My Contributions
Ok sorry but I'm not sure what you mean by different properties. This is what I've tried so far:
html

<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="index.html" id="current"></a><img alt="" src="images/App1.png" width="128" height="128" /></a></li>
<li><a href="/forum" onmouseover="forums.src='images/Forum.png' width='128' height='128'"><img alt="" src="images/Forum.png" width="100" height="100" id="forums" /></li>
<li><a href="#">Item three</a></li>
<li><a href="#">Item four</a></li>
<li><a href="#">Item five</a></li>
</ul>
</div>


That doesn't seem to be working though
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Help On Hover-Over Image Change.
28 Sep, 2008 - 07:41 AM
Post #10

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,026



Thanked: 82 times
Dream Kudos: 1175
My Contributions
@Mod - If we could split these topics I think that would be good, they are talking about the same general thing, but have totally different issues.

This is more that I meant:

CODE
<style>
  a{
    background: #eee;
    width: 100px;
    height: 20px;
  }
</style>

<a href="/forum" onmouseover="this.style.width='128'; this.style.height='128'">Test</a>


You are changing the CSS properties of the link on mouseover, which takes effect.

Notice - You need to have a semi-colon after each call for it to work correctly. Also, because it is treated as javascript (mostly because it is) it won't work on browsers that have javascript disabled.

Hope that helps.
User is offlineProfile CardPM
+Quote Post

webmin
RE: Help On Hover-Over Image Change.
28 Sep, 2008 - 07:50 AM
Post #11

D.I.C Head
**

Joined: 21 May, 2008
Posts: 96


My Contributions
still not working here's all the code for my index page:
CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<style>
a{
    width: 100px;
    height: 100px;
}
</style>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>

<body>
<center>
<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="index.html" id="current"></a><img alt="" src="images/App1.png" width="128" height="128" /></a></li>
<li><a href="/forum" onmouseover="this.style.width='128' this.style.height='128'"><img alt="" src="images/Forum.png" width="100" height="100" id="forums" /></li>
<li><a href="#">Item three</a></li>
<li><a href="#">Item four</a></li>
<li><a href="#">Item five</a></li>
</ul>
</div>
</center>
</body>

</html>

And here's the code in my css file:
CODE

#navcontainer
{
font-family: Arial,Sans-Serif;
margin: 0 auto;
width: 70%;
border-bottom: 1px solid #ddd;
}

#navlist
{
width: 60%;
text-align: center;
margin: 0 auto;
padding: 0;
text-indent: 0;
list-style-type: none;
}

#navlist li
{
padding: 0;
margin: 0;
text-indent: 0;
display: inline;
}

#navlist li a
{
letter-spacing: -1px;
text-decoration: none;
color: #ccc;
font-size: 1em;
padding: 0 2px;
border-top: .5em solid #eee;
}

#navlist li a:hover,#navlist a#current
{
/*color: #333;
border-top: none;
font-size: 1.5em;*/
}

#navlist a#current { color: #fc6; }

User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Help On Hover-Over Image Change.
28 Sep, 2008 - 07:58 AM
Post #12

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,026



Thanked: 82 times
Dream Kudos: 1175
My Contributions
All the code I gave you before does is increase the size of the link. What exactlty are you wanting it to do?
User is offlineProfile CardPM
+Quote Post

3 Pages V  1 2 3 >
Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:43AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month