PDA

View Full Version : [TUT] Create a simple rollover image [TUT]



Meti
26-07-2008, 06:45 PM
Hi,

Since my last rollover tutorial got closed, I decided to expand the tutorial, and make it better.
I will show you how to design the rollover images, and then, I'll tell you what codes you should add on your file.
Follow those steps, and you'll make it! :)
Good luck!
-----------------------------------------------------------------------
Step 1:
First of all, you need your rollover images. I've made a small tutorial for the designing part too. You could also do any images you want, but click HERE (http://metidesigns.com/tutorials/designing/index.htm) to see my tutorial. Follow the steps of designing the images.

Step 2:
I hope you've done the images, because it's time to do the coding bit now. First of all, you need to create a new file. Name it whatever you want it to be. Example: index.htm

Step 3:
Open up your file. If there already is some code in your file, remove it.

Step 4:
Add this code to your HTML file

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Rollover Image Tutorial</title>
</head>
<body>
</body>
</html>This is the the code which comes up everytime you create a new file with your program (DreamWeaver, FrontPage etc.)

Step 5:
Add this Javascript code between <head> </head>

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>This JavaScript code is very important for doing the rollover image, since it's the code which makes the images switch when you put your mouse over the image.

Step 6:
Now, you have to add this code between <body> </body>

<body onLoad="MM_preloadImages('box_hover.png')"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Rollover','','box_hover.png',1)"><img src="box.png" name="Rollover" width="94" height="21" border="0"></a>This code is what you see, on your screen, when you want to see the previews of what you've done.

Step 7:
You're done! Your full code should now look like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Rollover Image Tutorial</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body>
<body onLoad="MM_preloadImages('box_hover.png')"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Rollover','','box_hover.png',1)"><img src="box.png" name="Rollover" width="94" height="21" border="0"></a>
</body>
</html>If there's anything you need help with, don't hesitate contacting me!

[I]Copyright © MetiDesigns.com 2008+

Merged by Invent (Forum Moderator). Threads merged due to forum lag.

Tom-743
26-07-2008, 06:47 PM
I like the way you've explained the steps clearly, but you still havnt explained what the javascript actualy does.

Janczyk
26-07-2008, 06:55 PM
You've just told people to insert codes into their work without explaining what it does... :S

wsg14
26-07-2008, 07:01 PM
It's so much easier to do it in CSS.

Source
26-07-2008, 07:02 PM
It's so much easier to do it in CSS.

^ Listen to him. Even though we've been over this before in the last thread :/ Plus CSS leave's a smaller footprint over a large page.

Stepheen
26-07-2008, 07:04 PM
can't this be done just by changing li like
li {
before hovered css
}
li hover {
hovering css
}

It'd make more sense imo.

Dentafrice
26-07-2008, 07:06 PM
You still haven't explained what the Javascript does..

It looks better.. but you still haven't accomplished the task of fully explaining your topic, and doing it in CSS is easier.. and faster, and does not require JS to be on.

Meti
26-07-2008, 07:07 PM
You could also do it in CSS:
<style type="text/css">
li a:hover {
background-image: url('hover.png');
}
.roll {background-image: url('original.png');
}
</style>
<li class="roll">TEXT</li>

wsg14
26-07-2008, 07:09 PM
CSS:


.image {
background-image: url(image.png);
width: 50px;
height: 50px;
background-position: top;
}

.image:hover {
background-image: url(image.png);
width: 50px;
height: 50px;
background-position: bottom;
}
The reason I have backgorund-position is because it only has to load one image, instead of having the normal image and the image you get when you hover over. So when you hover over the image it doesn't 'blink' (don't know how to describe).
i.e. http://images.fansitegroup.com/header.png

HTML


<div class="image"></div>

Tom-743
26-07-2008, 07:18 PM
You could also do it in CSS:
<style type="text/css">
li a:hover {
background-image: url('hover.png');
}
.roll {background-image: url('original.png');
}
</style>
<li class="roll">TEXT</li>
Are you going to explain what it does? becuase its not realy a tut unless you do.

CoolHostUK-Dom
26-07-2008, 07:31 PM
How is that a tutorial?

Dreamweaver plonks that on your page when your doing it..

Calon
26-07-2008, 07:33 PM
How is that a tutorial?

Dreamweaver plonks that on your page when your doing it..
He's showing you how to use the code, but he's used dreamweavers source.

Would be best in CSS, but I'm not here to argue.

Meti
26-07-2008, 07:35 PM
Yes, but for those guys who don't have DreamWeaver, this will help them out.

CoolHostUK-Dom
26-07-2008, 07:35 PM
So this isnt a tutorial...

AND you could just use:


<img src="path/to/normal/img" onmouseover="path/to/mouseover/img" onmouseout="path/to/normal/img" />

Dentafrice
26-07-2008, 07:37 PM
[TUT] how many of these damn things are you going to make [TUT]

:|

Meti
26-07-2008, 07:39 PM
I pressed Post thread once - It didn't create the thread.
I pressed again, two threads were made.
This is the thread I want to use more than the other one.

CoolHostUK-Dom
26-07-2008, 07:39 PM
[TUT] how many of these damn things are you going to make [TUT]

:|

Agreed. And their all for the same bloody thing

EDIT: Then how are they different font sizes?
EDIT #2: Thanks simon for merging :)

Protege
26-07-2008, 07:48 PM
All the 'tutorials' you have posted are total ********, sorry but copying and pasting isn't teaching no one. However YOU don't even understand that code - let alone the people your attempting to teach.

Smell failure.

That javascript could be simplified to zero or a function.

Meti
27-07-2008, 03:16 PM
I know you can do this on DreamWeaver really fast.. but i'm doing this tut, most for the people who don't have those programs as DreamWeaver.

CoolHostUK-Dom
27-07-2008, 04:40 PM
However YOU don't even understand that code


I know you can do this on DreamWeaver really fast.. but i'm doing this tut, most for the people who don't have those programs as DreamWeaver.

METI, did you NOT read what he just said?

Calon
27-07-2008, 04:50 PM
METI, did you NOT read what he just said?Dom, stop picking on newbies.

At one time we never knew what HTML was, and we've taken our time to learn, so will this guy probably.. but a little longer than us.

Tom-743
27-07-2008, 06:03 PM
I know you can do this on DreamWeaver really fast.. but i'm doing this tut, most for the people who don't have those programs as DreamWeaver.
Most people use css and don't need dreamweaver to generate code for them.

Meti
27-07-2008, 06:37 PM
METI, did you read what he just said?
Ofcourse I did

Excellent1
27-07-2008, 06:41 PM
You really need to understand the code before calling it your own tutorial. It should have been a 'dreamweaver' tutorial. But on the other hand he is saying he did this for people who don't have dreamweaver and can't code..

Tom-743
27-07-2008, 06:43 PM
Ofcourse I did
What is the point of this tut, people who can't code can just get it from dreamweaver and people who can code can just make there own. And its not even a tut becuase you copy pasted the code from dreamweaver.

L?KE
27-07-2008, 07:57 PM
What is the point of this tut, people who can't code can just get it from dreamweaver and people who can code can just make there own. And its not even a tut becuase you copy pasted the code from dreamweaver.

I was literally just going to say this.

Tut: fail.

You've just told people where to put stuff, you haven't even explained it.

And if you wanted to get away with stealing dreamweaver's code you could have at least changed the function names or something, lols.

;)

Jahova
28-07-2008, 05:59 AM
Tbh, I see why your last tutorial got closed.
Because this actually isn't classed as a tutorial.

Tutorial's explain each part of the code, in detail about what it does and if you have to include it or not or even if you have to add it.

This doesn't, so therefore, I think you should re-look over the tutorial and think about adding this.

Calon
28-07-2008, 06:38 AM
Tbh, I see why your last tutorial got closed.
Because this actually isn't classed as a tutorial.

Tutorial's explain each part of the code, in detail about what it does and if you have to include it or not or even if you have to add it.

This doesn't, so therefore, I think you should re-look over the tutorial and think about adding this.
Agreed.

Meti
28-07-2008, 09:10 AM
Ok. I've heard all of your thoughts now. I don't want this Thread to be closed, so please stop discussing those things.

Off-topic:
@TomSpit:
Your signature where you say "Own rep to:"
Independent has changed name to calon ;)

Tom-743
28-07-2008, 09:17 AM
Ok. I've heard all of your thoughts now. I don't want this Thread to be closed, so please stop discussing those things.

Off-topic:
@TomSpit:
Your signature where you say "Own rep to:"
Independent has changed name to calon ;)
Sorry, but this thread should be closed, theres no way that this is a tut.

L?KE
28-07-2008, 09:18 AM
Sorry, but this thread should be closed, theres no way that this is a tut.

LOL agreed.

iTech
28-07-2008, 01:56 PM
This is more of a resource and how to put it in.
Explain what it does.

Want to hide these adverts? Register an account for free!