第一个帖子,第一个问题。
我是 jQuery 初学者,所以请耐心等待。我有一个有 3 个选项的菜单。我需要代码来切换它们 - 当一个选项处于活动/激活状态时,另一个选项处于非活动/停用状态(停用时,运行相应的 *_deactivate() 函数)。为了有一个整洁的菜单,我创建了输入/输出动画。我检查了一些帖子,但无法将解决方案应用于我的问题。
菜单代码:
// Menu button "A Empresa" mouse events ├───────────────────────────────────────────────────────────────────┤
$('#aEmpresa').on('mouseenter', function(){
$(this).css({'cursor':'pointer'});
$("#aEmpresa p").animate({'color':'#EF7F1A'}, 150);
$("#aEmpresa_underline").animate({'background-position-x':'0px', 'background-position-y':'-10px'}, 150);
});
$('#aEmpresa').on('mouseleave', function(){
$("#aEmpresa p").animate({'color':'#C5C6C6'}, 150);
$("#aEmpresa_underline").stop(true).animate({'background-position-x':'0px', 'background-position-y':'0px'}, 150);
});
$('#aEmpresa').on('click', function(){
$("#aEmpresa p").animate({'color':'#000000'}, 150);
$("#aEmpresa p").css({'font-weight':'bold'}, 150);
$('#aEmpresa_underline').animate({'background-position-x':'0px', 'background-position-y':'-22px'}, 150);
$(this).unbind('mouseenter mouseleave');
$(this).css({'cursor':'default'});
});
function aEmpresa_deactivate(){
$('#aEmpresa_underline').animate({'background-position-x':'0px', 'background-position-y':'-10px'}, 150);
$("#aEmpresa p").animate({'color':'#EF7F1A'}, 150,
function(){
$('#aEmpresa_underline').animate({'background-position-x':'0px', 'background-position-y':'-22px'}, 150);
$("#aEmpresa p").animate({'color':'#C5C6C6'}, 150);
$("#aEmpresa p").css({'font-weight':'normal'}, 150,
function(){
$('#aEmpresa').on();
$(this).css({'cursor':'pointer'});
}
);
}
);
}
// Menu button "A Nossa Arte" mouse events ├────────────────────────────────────────────────────────────────┤
$('#aNossaArte').on('mouseenter', function(){
$(this).css({'cursor':'pointer'});
$("#aNossaArte p").animate({'color':'#EF7F1A'}, 150);
$("#aNossaArte_underline").animate({'background-position-x':'0px', 'background-position-y':'-10px'}, 150);
});
$('#aNossaArte').on('mouseleave', function(){
$("#aNossaArte p").animate({'color':'#C5C6C6'}, 150);
$("#aNossaArte_underline").stop(true).animate({'background-position-x':'0px', 'background-position-y':'0px'}, 150);
});
$('#aNossaArte').on('click', function(){
$("#aNossaArte p").animate({'color':'#000000'}, 150);
$("#aNossaArte p").css({'font-weight':'bold'}, 150);
$('#aNossaArte_underline').animate({'background-position-x':'0px', 'background-position-y':'-22px'}, 150);
$(this).unbind('mouseenter mouseleave');
$(this).css({'cursor':'default'});
});
function aNossaArte_deactivate(){
$('#aNossaArte_underline').animate({'background-position-x':'0px', 'background-position-y':'-10px'}, 150);
$("#aNossaArte p").animate({'color':'#EF7F1A'}, 150,
function(){
$('#aEmpresa_underline').animate({'background-position-x':'0px', 'background-position-y':'-10px'}, 150);
$("#aNossaArte p").animate({'color':'#C5C6C6'}, 150);
$("#aNossaArte p").css({'font-weight':'normal'}, 150,
function(){
$('#aNossaArte').on();
$(this).css({'cursor':'pointer'});
}
);
}
);
}
// Menu button "Contactos" mouse events ├───────────────────────────────────────────────────────────────────┤
$('#contactos').on('mouseenter', function(){
$(this).css({'cursor':'pointer'});
$("#contactos p").animate({'color':'#EF7F1A'}, 150);
$("#contactos_underline").animate({'background-position-x':'0px', 'background-position-y':'-10px'}, 150);
});
$('#contactos').on('mouseleave', function(){
$("#contactos p").animate({'color':'#C5C6C6'}, 150);
$("#contactos_underline").stop(true).animate({'background-position-x':'0px', 'background-position-y':'0px'}, 150);
});
$('#contactos').on('click', function(){
$("#contactos p").animate({'color':'#000000'}, 150);
$("#contactos p").css({'font-weight':'bold'}, 150);
$('#contactos_underline').animate({'background-position-x':'0px', 'background-position-y':'-22px'}, 150);
$(this).unbind('mouseenter mouseleave');
$(this).css({'cursor':'default'});
});
function contactos_deactivate(){
$('#contactos_underline').animate({'background-position-x':'0px', 'background-position-y':'-10px'}, 150);
$('#contactos p').animate({'color':'#EF7F1A'}, 150,
function(){
$('#aEmpresa_underline').animate({'background-position-x':'0px', 'background-position-y':'-10px'}, 150);
$("#contactos p").animate({'color':'#C5C6C6'}, 150);
$("#contactos p").css({'font-weight':'normal'}, 150,
function(){
$('#contactos').on();
$(this).css({'cursor':'pointer'});
}
);
}
);
}
// Running menu for the first time - aEmpresa ├─────────────────────────────────────────────────────────────┤
function aEmpresa_runFirstTime(){
$('#aEmpresa_underline').animate({'background-position-x':'0px', 'background-position-y':'-10px'}, 150);
$("#aEmpresa p").animate({'color':'#EF7F1A'}, 150,
function(){
$('#aEmpresa_underline').animate({'background-position-x':'0px', 'background-position-y':'-22px'}, 150);
$("#aEmpresa p").animate({'color':'#000000'}, 150);
$("#aEmpresa p").css({'font-weight':'bold'}, 150,
function(){
$('#aEmpresa').off();
$(this).css({'cursor':'default'});
}
);
}
);
}
// Running first time
aEmpresa_runFirstTime();
佩德罗
PS 第一次运行时,第一个选项会自动激活。