/    Sign up×
Community /Pin to ProfileBookmark

Is it possible to set hover state when not hovered?

I am trying to create a javascript drop down menu. I am using the javascript from this site:

[url]http://www.dynamicdrive.com/dynamicindex1/dropmenuindex.htm[/url]

If you go there you will notice an example menu when you hover over the button “Get the news”. The button image changes when the menu is open.

I want to do something like this, but the problem is that my image is one large image and I use CSS to select different parts of it depending on the state.

For instance when there is no hover it would be like
a{
background: url(image.gif) 0px 0px
}

and for hovering:
a:hover{
background: url(image.gif) 0px 50px
}

The image leaves the hovered state when you move off of it and start selecting menu items, unlike the example on the webpage which uses different urls to swap images.

Is there a way I can set the hover state of the image when the menu is open. Any other suggestions?
Thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mrhooAug 08.2009 — use a: hover,a: focus{background: url(image.gif) 0px 50px}

You can call focus() on an a element from a script.
Copy linkTweet thisAlerts:
@M123authorAug 10.2009 — That works. Thanks for the help!
×

Success!

Help @M123 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 5.24,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...