Help - Search - Members - Calendar
Full Version: Mouseover Image Code
Zymic Webmaster Forums > Web Design & Development > Client Side Scripting > HTML and CSS
Drake14
What's the HTML code so when i move my mouse over an image, the image will change into something else, like a different color or something.
IamShipon1988
Well you could do it using Javascript or CSS. Here's how
Javascript
CODE
Place the following in your <head> section
<!-- Begin

image1 = new Image();
image1.src = "images/image_hover.gif";

// End -->
</script>

In <body>
<a href="http://YOUR_URL.ext/SUBDIR/ onmouseover="image1.src='images/image_hover.gif';"
onmouseout="image2.src='images/regularimage.gif';">
<img name="image2" src="images/regularimage.gif" border=0 width="88" height="31"></a>

So just replace image_hover.gif and regularimage.gif with your own image directory.

CSS
CODE
in stylesheet

#image a {
display: block;
width: 80px;
height: 33px;
background-image: url("image/image.gif");
}
#image a:hover {
background-image: url("image/image_hover.gif");
}

HTML would be
<div id="image">
<a href="#">text</a>
</div>
bezz
A better way to do it using only one image (better in that the image is always preloaded needing no javascript).
http://www.tutorio.com/tutorial/pure-css-image-rollovers
EMOruffino
kinda what bezz is talking about... check out this sexy menu with source:

http://www.webdesignerwall.com/tutorials/advanced-css-menu/


DEMO: http://emoruffino.com/zymic/menu/
(im going to start using this method)
IamShipon1988
QUOTE(EMOruffino @ Jan 3 2008, 05:14 PM) *
kinda what bezz is talking about... check out this sexy menu with source:

http://www.webdesignerwall.com/tutorials/advanced-css-menu/
DEMO: http://emoruffino.com/zymic/menu/
(im going to start using this method)

I was thinking for a second, wait he didn't make this; Nick did. Then I noticed the first link you posted. You really shouldn't steal any content without his permission. He will get angry, and trust me, you don't want him angry...lol. Anyways...what BEZZ said is exactly what I was trying to show with the CSS portion of my previous post. You can either do that with JS or CSS. Many would prefer using CSS because it's easier and a lot better than JS. What you have to also note is that many browsers now grants the user the option to disable JS on their computer. However, CSS cannot be disabled (as of now).
bezz
QUOTE(IamShipon1988 @ Jan 5 2008, 02:00 AM) *
I was thinking for a second, wait he didn't make this; Nick did. Then I noticed the first link you posted. You really shouldn't steal any content without his permission. He will get angry, and trust me, you don't want him angry...lol. Anyways...what BEZZ said is exactly what I was trying to show with the CSS portion of my previous post. You can either do that with JS or CSS. Many would prefer using CSS because it's easier and a lot better than JS. What you have to also note is that many browsers now grants the user the option to disable JS on their computer. However, CSS cannot be disabled (as of now).

Your example isn't the same as mine. Yours uses 2 graphics, one when the mouse is not over the image, and another one when it is over the image. This creates the problem that the browser has to load the mouse over image seperately when it is moused over the first time, causing a delay. My example uses masking, and moves the image up when moused over, no extra loading on the fly needed.
IamShipon1988
Ah now I see what it does. It literally rolls over. I never actually thought about using such techniques. I have read that tutorial once before, but that was a long time ago. Anyways, thank you very much.
EMOruffino
QUOTE(IamShipon1988 @ Jan 5 2008, 01:00 AM) *
I was thinking for a second, wait he didn't make this; Nick did. Then I noticed the first link you posted. You really shouldn't steal any content without his permission.


how did i? you can download the source... so i put it on my server... lmao....
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.