I am building a website with hover effects. See http://vitaminjdesign.com/index.html and look at the services section in the bottom right. I am using :hover to change the background color. I want to use jquery to acheive the same result with an elegant fade. Here is my html:
<div class="iconrow">
<a href="#"><img src="images/icon1.png" border="0" width="35" />
<h2>Website Design</h2></a>
</div>
(repeated 6 times with different images and text)
Basically, when .iconrow is rolled over, I want the background to change from none to background-color: #cccccc; and when it is rolled off, back to none.
Note: I built and tested my solution via Firebug to work on the link you provided. If you follow these steps in order, you should have it fully working
You will not be able to animate from
transparentto a color except in Safari and Firefox 3.5 and other browsers that support RGBA background colors. If you are looking for a cross browser support, then I would attack the problem like this:1. Have your default hover effects scoped by a non-js class, so the
:hovereffects will work as a fall-back. A great way to do this is as follows:This changes
no-jstojsbefore the page even displays.2. Use jQuery to add dummy elements along side your
atags (jsto add the dummy element is in step 3)Here is the CSS to use:
3. Fade in and out the new dummy element on
mouseenterandmouseleaveFinally, be careful if you decide to use an image background instead of the solid color. IE7 and IE8 cannot alter the opacity of 24bit PNG files. It completely screws up the transparency.