View Full Version : jQuery Image Fading

12-12-2011, 10:02 AM
I have struggled and struggled to find a script which creates a simple faded button (where the image is in the background attribute) for a long time.

Everything that I have found has used some weird attempt through add class and remove class which results inevitably in a fade through black (not what I wanted).

So... I came up with a simple device (a bit of a cheat) for avoiding needing to fade through black or use complex jQuery functions.

The reason I wanted this to be in the background image is because I want a crisp site in which images are not dragable or easily copied.
It is also a tool which could be used outside of the navigational concept shown.


This example creates 2 buttons though the method is not limited to 2 (advise changing the l or r to a number or representative letter for more than two i.e. index: i about: a.
The two buttons in this example are a simple left right method.
To event catching div in this method will always be #nav_?_inv.
The inv suffix stands for Invisible! Though it is visible to the browser it must remain invisible to any human. It cannot hold an image or BG colour.
The mouseenter and mouseleave events can be changed to mouseover and mouseout respectively.
CSS positioning is crucial (this is why I have used absolute and margins to position my divs.
All CSS rules MUST be applied to all divs regarding size and position
An example of the working script is currently (12/12/11) available here (http://web.xipux.co.uk/index.php), though I cannot guarantee it will stay.

<!-- navigation -->
<div id='nav_l_bot'></div>
<div id='nav_l_top'></div>
<div id='nav_l_inv'></div>
<div id='nav_r_bot'></div>
<div id='nav_r_top'></div>
<div id='nav_r_inv'></div>

position: absolute;
width: 50px;
height: 50px;
margin: 515px 0px 0px 100px;
background:url(../images/nav_l_up.png) center no-repeat;

position: absolute;
width: 50px;
height: 50px;
margin: 515px 0px 0px 450px;
background:url(../images/nav_r_up.png) center no-repeat;

// All the same as nav_l_bot except hover image below
background:url(../images/nav_l_ho.png) center no-repeat;

// All the same as nav_r_bot except hover image below
background:url(../images/nav_r_ho.png) center no-repeat;

// All the same as nav_l_bot except NO image

// All the same as nav_r_bot except NO image


// set tops to gone!

// left nav over

// left nav out

// right nav over

// right nav out


I hope other people find this helpful!

12-13-2011, 01:32 PM
Please do let me know if you think this has been helpful to you.

Also if you have any questions over the application of this then do not hesitate to ask.