/    Sign up×
Community /Pin to ProfileBookmark

rollover image menu with current page active

Hi there
I’ve created a nav bar for this site – [url]http://web11.3essentials.com/~cp27358/[/url] – I’m using javascript to handle the image rollover which is working just fine. However I want to add to this so that the current page will stay with the second or rollover image. How would you suggest I edit or add to my code so it keeps the second image active if it is the active page?

In my script file this is what I’m using for an image:

menu1buttonup = new Image();
menu1buttonup.src = “http://web11.3essentials.com/~cp27358/wp-content/themes/origin/images/menu1.jpg” ;
menu1buttondown = new Image() ;
menu1buttondown.src = “http://web11.3essentials.com/~cp27358/wp-content/themes/origin/images/menu1a.jpg” ;

followed by….

function buttondown( buttonname )
{
if (document.images) {
document[ buttonname ].src = eval( buttonname + “down.src” );
}
}
function buttonup ( buttonname )
{
if (document.images) {
document[ buttonname ].src = eval( buttonname + “up.src” );
}
}

and this is what my list items look like:

<a href=”<?php echo home_url(); ?>/?page_id=7″ onmouseover=”buttondown(‘menu1button’)”
onmouseout=”buttonup(‘menu1button’)”><img src=”<?php bloginfo(‘template_url’); ?>/images/menu1.jpg” name=”menu1button” /></a>

thank you

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ijsMay 27.2011 — You don't need JS for it. The solution is simple and you can use only css, look:

1) Make hover state.

html (add class to button):
[code=html]<div class="mainMenu"></div>[/code]

css (set background image for the button):
[code=html]
.mainMenu {
width: 192px;
height:21px;
background-image: url(menu1_normalState.jpg);
}
[/code]


change the image for hover state or active page:
[code=html]
.mainMenu:hover, .mainMenuActive{
width: 192px;
height:21px;
background-image: url(menu1_hoverState.jpg);
}[/code]


2) If you on another page, just change class of div from .mainMenu to .mainMenuActive
×

Success!

Help @Colin_Bondi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...