Reply
Button animation help!!
Old 07-25-2006, 03:40 AM Button animation help!!
Novice Talker

Posts: 8
Hey

I've got a web page that contains links. I've found a script I can use to make the links change color when the mouse is over.

The page is:
www.laasanen.net/alina/paasivu.html

One of the links contain script which is the red one. As you can see it turns grey when the mouse is over it.

The script I'm using is:

<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.b1.src ="b_blue.gif"
}
function mouseOut()
{
document.b1.src ="b_pink.gif"
}
</script>
</head>

<body>

<a href="http://www.w3schools.com" target="_blank"
onmouseover="mouseOver()"
onmouseout="mouseOut()">
<img border="0" alt="Visit W3Schools!" src="b_pink.gif" name="b1" width="26" height="26" /></a>

</body>
</html>

I'm having trouble making using this code at least twice on the same page. How is this done? The thing that happens for me is that the next link I make does not change color when the mouse is over it but the first link I made, which is now seen on the web page, changes color, even though the mouse is over the other link. I hope this made sense at all. I really need help. I guess the question is that how do I use this script on several links o the same page??
-Al
Allu is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 07-25-2006, 08:39 AM Re: Button animation help!!
funkdaddu's Avatar
Web Design Snob

Posts: 636
I wouldn't use mouseOver as the name of your function as that is an object property. It can confuse things. You need to use function parameters to pass specific data along for each image:
Code:
function swapImg(targetImg, imgToSwap) {
     targetImg.src = imgToSwap;
}
Then you use it in your code like:
HTML Code:
<img src="yourImgName.gif" onmouseover="swapImg(this,'yourImgName-over.gif')" onmouseout="swapImg(this,'yourImgName.gif')" >
There are many ways to do this but this is the simplest example. The 'this' passes a reference of the object to the function.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 07-26-2006, 04:06 AM Re: Button animation help!!
Novice Talker

Posts: 8
Hey

Thanks for the help.

I was just wondering (because this JS is very new to me) that do I have to anything to the actual code or do I just paste it between the script tags just like that?
Allu is offline
Reply With Quote
View Public Profile
 
Old 07-26-2006, 08:33 AM Re: Button animation help!!
funkdaddu's Avatar
Web Design Snob

Posts: 636
Yes, just put the function between the <script> tags, and then modify your images with the onmouseover="swapImg(this,'yourImgName-over.gif')" onmouseout="swapImg(this,'yourImgName.gif')" for each rollover you want.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Reply     « Reply to Button animation help!!
 

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12194 seconds with 13 queries