
|
View Full Version : Image Rollovers
ScionStatic(Stevo) 11-26-2004, 02:32 PM I finally got my layout done :D and with the image links on the left im going to create a rollover for them. I used this > http://corporate.setel.com/tools/jsgen/rollover_generator.php < to make the rollover javascript. With my site layout > http://www.stevonio.com/final/final.html < how can i get it in there without scrambling the images? I tried once replacing the image html (leaving the ending table tabs) with the javascript image part but it got scrambled everywhere. How can i do this? :eek:
ScionStatic(Stevo) 11-27-2004, 03:32 PM Bump...i need to fix this ASAP
WebDesignGold 11-27-2004, 07:30 PM Suppose you call your "Onmouseover" image final_01_0n.gif, do the following first:
<!-- STEP ONE: Copy this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Administrator JavaScript Generator Suit -->
<!-- Rollover Generator -->
<!-- Fortune Design -->
<!-- www.fortunedesign.co.uk -->
<!-- Begin
image1 = new Image();
image1.src = "images/final_22_on.gif";
// End -->
</script>
</HEAD>
Continue with the the rest of the images in the same way..
image2 = new image();
image2.src = "images/final_25_on.gif";
etc...
Then, replace this (in your source code):
<A HREF="http://www.projects.stevonio.com"><IMG SRC="images/final_22.gif" WIDTH=87 HEIGHT=20 BORDER=0 ALT=""></A>
With this:
<a href="http://www.stevonio.com" onmouseover="image1.src='images/final_22_on.gif';"
onmouseout="image1.src='images/final_22.gif';">
<img name="image1" src="images/final_22.gif" border=0></a>
etc...
This should work.
ScionStatic(Stevo) 11-27-2004, 08:26 PM Wait, so you want me to put the :
<!-- STEP ONE: Copy this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Administrator JavaScript Generator Suit -->
<!-- Rollover Generator -->
<!-- Fortune Design -->
<!-- www.fortunedesign.co.uk -->
<!-- Begin
image1 = new Image();
image1.src = "images/final_22_on.gif";
// End -->
</script>
</HEAD>
: be4 all my other stuff, and put the same thing under it for all the other files. Then for the :
<a href="http://www.stevonio.com" onmouseover="image1.src='images/final_22_on.gif';"
onmouseout="image1.src='images/final_22.gif';">
<img name="image1" src="images/final_22.gif" border=0></a>
>
i put that where the images should go?
ScionStatic(Stevo) 11-27-2004, 08:27 PM Wait...lol, i just added the others in and now none of them work :eek: Did i do sumthin wrong?
And i just looked at it in IEXPLORE, and its messed up WTF!?
ScionStatic(Stevo) 11-27-2004, 09:26 PM It looks right in IEXPLORE when theres no javascript, but with it its a bit messed up . When i first tried he home button with javascript it worked, but when i added rest it stopped. :-(
Edit: It works with the first button when i put it on, but after that the rollover dosent work if i put one udner it.
ScionStatic(Stevo) 11-28-2004, 12:11 PM Anyone else know the solution?
the_pm 11-28-2004, 12:30 PM I can't see the rollover effect you're trying to achieve, so I can't see what you're trying to accomplish, but rollovers are best scripted by hand, IMHO. Most rollover effects can be handled purely by CSS, which is much more reliable (and produces much more efficient code) than going to JavaScript route. But if JavaScript is necessary (which is sometimes the case), it's almost always better done by hand.
How well do you understand these technologies?
ScionStatic(Stevo) 11-28-2004, 12:35 PM Never worked with CSS be4. Above is the code im using..look in the source of my webpage link above. The images on the left, home and projects etc. and supposed to turn blue when mouse goes over. But when i add more then one it stops working.
the_pm 11-28-2004, 12:40 PM Well, I have to ask, why use images of words when you can just use text? If you used text, changing colors would be as simple as something like this:
a { background:#000 ; color:#999 ; text-decoration:none }
a:hover { color:#09C }
I'm just guessing on the colors, of course. But it's really that simple in CSS using straight text. If you must use images of text (which makes absolutely no sense with your particular layout), you can still set up CSS rules for background image replacement, or you can set up some fairly simple JS functions to do the job as well.
ScionStatic(Stevo) 11-28-2004, 12:51 PM I think the text im using i got off a font site. I did the javascript...im pretty sure just like he said but after the first it dosent work. How would i go about this in CSS
the_pm 11-28-2004, 07:57 PM What I'm wondering is why use an image of text? All of those links down the side, "Home" "Projects" etc. are all images. Why not just use text? This will make a big difference how you achieve the rollover effect you want to create. It would be one thing if you were using a special font or a precise button effect, but it's very regular text on a plain background - no reason to use images.
If you use text, then code similar to what I gave a couple posts up will do the job. If you're completely unfamiliar with CSS, it's time to get the ball rolling on it. Simply put, you can't be an effective designer at any level if at the very least you don't comprehend how CSS works. That's just the nature of the beast nowadays :) Your code's already posted above - just switch to real text, and problem solved!
ScionStatic(Stevo) 11-28-2004, 08:05 PM The reason id rather have it as image is 1 people dont have that text, and 2 i plan soon to change the links to something no1 will have. So i need to get the image rollovers working.. sorry :-) Is there some other way to make a rollover with an image thatll work?
the_pm 11-28-2004, 08:28 PM Ok, if you want to go the CSS route, here's what you can do.
Create an image of each rollover with the regular state and rollover state side by side. Make sure they are the same size. So if the image you're using to link is 100x25 pixels, make the total image 200x25, with the two states next to each other. Then make a rule to attach to a spacer image on the screen, like this:
a.link1 { background:url(bg_image.ext) ; height:25px ; width:100px }
a.link1:hover { background:url(bg_image.ext) right }
Just for kicks, toss this into your style sheet:
a img { border:none }
That will keep all linked images from showing te default 1px blue border.
Then in your HTML code, you'll have a link like this:
<a href="somewhere.html" class="link1"><img src="spacer.gif" alt="appropriate alternative text"></a>
Then just repeat the process for all links involved. This is the foolproof way to make the rollover effect work without worrying about unreliability inherent in JavaScript.
If you do wish to go with JavaScript, the coding is a little less clean, and there are more than one way to do it. Here's one:
<a href="somewhere.html"><img src="linkimage1.ext" onmouseover="this.src=linkimage2.ext" onmouseout="this.src=linkimage1.ext" border="0"></a>
Again, the CSS version is much more reliable, and it's a little more efficient when you move the rollover function into its own master document, but I suppose going the JavaScript route won't hurt too bad. Does that help at all, or is it more confusing now?
ScionStatic(Stevo) 11-28-2004, 08:48 PM If i put that html part in my html, where does that CSS part go?
the_pm 11-28-2004, 09:09 PM Well, keep in mind that this is a generic framework. You can't simply plug it in and expect it to work. Your file paths need to be correct, your class declarations need to be unique and consistent from link to link.
The CSS part goes into his own document, given the .css extension, and linked to the HTML document. The most common way to do this is using <link rel="stylesheet" type="text/css" href="pathtoyourstylesheet/documentname.css">.
ScionStatic(Stevo) 11-29-2004, 08:23 AM Ok, so i add this into a css doucment
a.link1 { background:url(bg_image.ext) ; height:25px ; width:100px }
a.link1:hover { background:url(bg_image.ext) right }
change all the links blah blah
<a href="somewhere.html" class="link1"><img src="spacer.gif" alt="appropriate alternative text"></a>
With that.^..^.. what do i replace class with? And for image src does it go to the css document or one of the 2 rollover images?
P.S. Thanks 4 the link
the_pm 11-29-2004, 09:15 AM bg_image.ext is my generic name for the file you're switching back and forth. The image you see on the screen itself, generated in the HTML document is simply a transparent spacer with good alternative text that loads in the event images are not available.
It's much easier to show than to explain. I'm working on using this same effect on a site right now. You're welcome for the link - I'll be showing what I did and how I did it there, if you want to see it in action!
Edit: I think AListApart.com has an article devoted to this effect, but I can't seem to find it. It wouldn't hurt to take a peek over there and see, or maybe a kind soul with this knowledge will share it :)
|