I have a sprite image for each list item (home, services and contact). I’m using CSS to move the position on hover. It works fine except I would like fade the transition instead of rapidly moving the position. I am trying to make it look like the button is being pushed in on hover. I would like to slow it down. I have been all day on this and not getting anywhere. Thanks for any help!
HTML
<ul id="navigation">
<li class="link1"><a href="index.html">Home</a></li>
<li class="link2"><a href="services.html">Services</a></li>
<li class="link3"><a href="contact.html">Contact</a></li>
</ul>
CSS
li.link1 {
text-indent: -9999px;
background-image: url(../images/home.png);
background-repeat: no-repeat;
height: 15px;
width: 66px;
background-position: left top;
}
li.link1:hover {
background-image: url(../images/home.png);
background-repeat: no-repeat;
height: 15px;
width: 66px;
background-position: left bottom;
}
li.link2 {
Repeats itself...
Could you do it with relative positioning and CSS3 transitions?
Demo:
http://jsfiddle.net/jtbowden/gP9kD/
Update Demo with all three links and simplified CSS for the
lielements:http://jsfiddle.net/jtbowden/gP9kD/1/
jQuery
If you want a true
fadeeffect, you can do this with jQuery. I hacked together an example here:http://jsfiddle.net/jtbowden/gP9kD/4/
This example creates clones of each
lichanges the background-positioning, and absolutely positions them under the currentlielements and hides them. Then on hover, it fades the mainliout (to almost zero, so it still stays active), and fades in the one underneath.It is a little hacky, because the
liclones still contain the link, etc. But it works, and demonstrates the principle.