0

Hi all,

I am animating the bg color of some links. But I have changed the bg color of each link, so they have unique bg colors.

When I use the jq function i normally use, It doesnt work properly because I can only animate back to one specific color, which i had declared in the callback function..

So..I am asking: How do I save the background color of the element on hover, animate it, and change it back to the color saved in the variable:

$(document).ready(function(){
        $("#main_nav ul li a").hover(function() {
        // Doesnt this save the original color of the element being hovered?
var original_color = $(this).css('backgroundColor');

$(this).animate({ backgroundColor: "#069" }, 800);
},function() {
// How do I use the variable with the original color in here? - This doesnt work..
    $(this).animate({ backgroundColor: original_color }, 300);
});
});

Klemme

Edited by klemme

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by klemme
0

I believe it does. The way you defined is inside a
function which means it's a local variable and the only place you can use it is within the function that it's defined in. You need to have a global variable which you can access and change its value anywhere within your program. define the variable outside of your function and use it anywhere.

0

Thanks for the answer!

Im just a novice at javascript, and would have to ask you how exactly I do that..?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.