I have different "drawers" that slide open and closed in response to navigation links on my page. I'm using some jQuery to flip them open and closed, and change the page background and link colors depending on which "drawer" is open.
I'm also using some jQuery to fade the hover color on the links. Everything is working fine, except for getting the link to return to the NEW base color on mouseout. It always defaults to the original css value. So, I know I have to go into the following and change the .mouseout color depending on which color I want the link to return to on mouseout.
If I just set a variable like in the following example, all is well, it works beautifully.
var originalColor = "#123456";
jQuery.fn.linkFader = function(settings) {
settings = jQuery.extend({
returnColor: originalColor,
color: '#8dc63f',
duration: 600
}, settings);
return this.each(function() {
$(this).mouseover(function() { $(this).stop(true, true).animate({ color: settings.color },settings.duration); });
$(this).mouseout(function() { $(this).stop(true, true).animate({ color: settings.returnColor },settings.duration); });
$(this).click(function() { $(this).stop(true, true).animate({ color: settings.color },settings.duration); });
});
};
$(document).ready(function() {
$('.fader').linkFader({
});
});
BUT... If I try to assign the variable "originalColor" like the following, it fails. I need the script to figure out which "drawer" is open, and set the variable to the proper color. What am I doing wrong here?
var originalColor='';
if($('#drawerA').is(":visible")){
var originalColor = "#123456";
}
if($('#drawerB').is(":visible")){
var originalColor = "#456789";
}
if/elseinstead of 2ifs. If I'm right, it will always take theelseclause.varkeyword in front of the assignments in theifstatement bodies.alert('A')to the case where drawer A is visible and make sure that code is running.visibility: hiddenare considered visible. api.jquery.com/visible-selector