jQuery Animated Rollover

by Matt 26. December 2008 14:35

Here is an example of how to animate the rollover event of an element using jQuery:


<script src="jquery-1.2.6.js" type="text/javascript"></script>
<script src="jquery.color.js" type="text/javascript"></script>

$(document).ready(function()
{
    $(".menuButton").hover(
        function()
        {
            $(this).animate(
                {
                    backgroundColor: "#9D9D9D"
                }, 300);
        },
        function()
        {
            $(this).animate(
                {
                    backgroundColor: "#BEBEBE"
                }, 900);
        }
    );
});

The above code will select all elements that use my "menuButton" CSS class.  This can be any class name, or you can select elements by id, etc.

To be able to set the background color in the animate method, you will need the following jQuery plug-in: http://plugins.jquery.com/project/color.

Comments

7/6/2010 1:02:06 PM #

Great article, this has to be THE single best article online.. thanks dude!

essay writing tips

7/6/2010 7:53:20 PM #

Hello. This is kind of an "unconventional" question , but have other visitors asked you how get the menu bar to look like you've got it?

Ayesha Antczak

7/12/2010 2:53:49 AM #

I wish I understood all this...

Basement Dehumidifiers

7/15/2010 1:00:45 AM #

thanks for sharing the code

Nike Air Force

7/29/2010 8:34:39 AM #

Thank you for this wonderful posts. Really made my spare time one pleasant experience.

podlozky na stol

Add comment




biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.0.7
Original Theme by Mads Kristensen | Modified by Crafty Coders