Blog

Home > Javascript  > Nice link colour fades using jQuery

As I’m sure you know, it’s very easy to set a different colour for a link when a user hovers over it using the :hover pseudo class – it’s used pretty much everywhere.

However, wouldn’t it be nice if instead of jumping sharply from one colour to another, the colours subtly fades from one to another and back again? Fortunately I have written a very simple plugin to do just that!

This plugin subtly fades from the default colour of the element to the specified colour when a user hovers over it, and back again when the user leaves the element.

Demonstration


EXAMPLE LINK 1
EXAMPLE LINK 2 – SLOW FADE BACK

Using the plugin

This plugin required the color animations official jquery plugin, available at http://plugins.jquery.com/project/color. This must be included on the page before the plugin is included.

To use the plugin, simple use the following code:

$('a').hoverFadeColor();

This will make all the links on a page fade to the color specified in the css:hover style and back again.

The options are as follows:

color: the color to fade to on hover. This can be any css color, rgb value or hexadecimal value. If it is not specified, the plugin will use the default css hover value.

fadeTospeed (default 300): the rate at which the element fades to the hover color

fadeFromspeed (default 700) is the rate at which the element fades to the default color

Download

Version 1.1. Released 29 June 2011

9 Comments

  • December 27, 2010at6:19 am

    hi how are ya.

    Im using this in my website, any idea to implement it in divs? cool would be !

    bye

  • August 13, 2011at8:52 am

    I’m pretty new to javascript coding. So should I include the jquery “color” script, and then your code in the head of the document? And then place:

    $(‘a’).hoverFadeColor();

    somewhere in the body of the document BUT before any links? is that right?

  • sl

    Reply
    August 14, 2011at6:34 pm

    Hi, im using this too, but some time function is stopping , color not fade .Maybe you know how eliminate this problem

  • Jeff

    Reply
    August 31, 2011at8:14 pm

    When you hover out from a visited link, the visited link color is replaced by the default link color. Is there any way to work around this?

  • September 30, 2011at8:21 am

    Hi! Very useful script, thx! Is it compatible also with IE8? It seems not… 🙁

  • Mike

    Reply
    October 28, 2011at2:51 pm

    Thank you mate, I’ve been looking for something like this for ages!

Post a Comment