Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
tidying my rollover code
Old 02-15-2004, 05:27 AM tidying my rollover code
wicko3's Avatar
The Wickmeister

Posts: 368
Location: Derby, UK
Trades: 0
Hi guys,

I have made this simple javascript rollover script. It works great, but its a little long. I was wondering if anyone knew how to shorten it, perhaps by using loops. There certainly is a lot o' repetition in there!

Code:
<script language="JavaScript">
<!-- Rollover generator
pic1on = new Image(122,29)
pic1on.src = "images/mnu_aboutme_on.gif"
pic1off = new Image(122,29)
pic1off.src = "images/mnu_aboutme_off.gif"
pic2on = new Image(112,29)
pic2on.src = "images/mnu_services_on.gif"
pic2off = new Image(112,29)
pic2off.src = "images/mnu_services_off.gif"
pic3on = new Image(127,29)
pic3on.src = "images/mnu_portfolio_on.gif"
pic3off = new Image(127,29)
pic3off.src = "images/mnu_portfolio_off.gif"
pic4on = new Image(166,29)
pic4on.src = "images/mnu_testimonials_on.gif"
pic4off = new Image(166,29)
pic4off.src = "images/mnu_testimonials_off.gif"
pic5on = new Image(157,29)
pic5on.src = "images/mnu_contact_on.gif"
pic5off = new Image(157,29)
pic5off.src = "images/mnu_contact_off.gif"
function menu1on() {
document.menu1.src = pic1on.src;
return true;
}
function menu1off() {
document.menu1.src = pic1off.src;
return true;
}
function menu2on() {
document.menu2.src = pic2on.src;
return true;
}
function menu2off() {
document.menu2.src = pic2off.src;
return true;
}
function menu3on() {
document.menu3.src = pic3on.src;
return true;
}
function menu3off() {
document.menu3.src = pic3off.src;
return true;
}
function menu4on() {
document.menu4.src = pic4on.src;
return true;
}
function menu4off() {
document.menu4.src = pic4off.src;
return true;
}
function menu5on() {
document.menu5.src = pic5on.src;
return true;
}
function menu5off() {
document.menu5.src = pic5off.src;
return true;
}
//-->
</SCRIPT>
I call each function in my <body> like this:

Code:
<a href="portfolio.htm" onmouseover="menu3on()"
onmouseout="menu3off()"><img border="0" name="menu3"
src="images/mnu_portfolio_off.gif" alt="Portfolio" width="127"
height="29"></a>
Thanks a lot,

Wicko3
wicko3 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to tidying my rollover code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB 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.07970 seconds with 12 queries