I'd like to change the background position of a CSS-class while hovering a li-element.
HTML:
<div id="carousel">
<ul id="submenu">
<li>Apple</li>
<li>Orange</li>
</ul>
</div>
CSS:
#carousel {
float: left;
width: 960px;
height: 360px;
background: url(../images/carousel.png);
}
Any suggestions on how to do this?
rebellion's answer above won't actually work, because to CSS, 'background-position' is actually shorthand for 'background-position-x' and 'background-position-y' so the correct version of his code would be:
It took about 4 hours of banging my head against it to come to that aggravating realization.
You guys are complicating things. You can simple do this from CSS.
Here you go:
Sets new value for
backgroundPosition
on thecarousel
div when a li in thesubmenu
div is hovered. Removes thebackgroundPosition
when hovering ends and resetsbackgroundPosition
to old value.