我是 javascript 和 jQuery 的新手,所以这个问题可能看起来很愚蠢,但我找不到任何例子或文档。
我得到了这个功能,用于进行一点彩色动画翻转和展开,效果很好:
$(".box_nav").hover(function(){
jQuery(this).stop(true, false);
$(this).animate({ backgroundColor: "#fff"}, 300 ); },
function() {
jQuery(this).stop(true, false);
$(this).animate({ backgroundColor: "#000"}, 300 ); }
);
事实上,如果我最近添加了一个样式表更改按钮,它也可以正常工作:
$(".black-white").click(function(){
$("link").attr("href", "<?php bloginfo("template_url"); ?>/css/styles-black-white.css");
$(".wp-polls-loading").css({ display:"none"});
return false;
});
$(".grey-white").click(function(){
$("link").attr("href", "<?php bloginfo("template_url"); ?>/css/styles-grey-white.css");
$(".wp-polls-loading").css({ display:"none"});
return false;
});
关键是我想在我的翻转菜单上创建一个条件,以便我也可以切换它的颜色。
所以我尝试了这样的几件事:
/////////////////////////////////////////////////////////////////////////////
//Stylesheet change
$(".black-white").click(function(){
$("link").attr("href", "<?php bloginfo("template_url"); ?>/css/styles-black-white.css");
$(".wp-polls-loading").css({ display:"none"});
var tt = "black";
return false;
});
$(".grey-white").click(function(){
$("link").attr("href", "<?php bloginfo("template_url"); ?>/css/styles-grey-white.css");
$(".wp-polls-loading").css({ display:"none"});
var tt = "grey";
return false;
});
/////////////////////////////////////////////////////////////////////////////
//Over menu
if (tt == "black"){
$(".box_nav").hover(function(){
jQuery(this).stop(true, false);
$(this).animate({ backgroundColor: "#fff"}, 300 ); },
function() {
jQuery(this).stop(true, false);
$(this).animate({ backgroundColor: "#000"}, 300 ); }
);
}else {
$(".box_nav").hover(function(){
jQuery(this).stop(true, false);
$(this).animate({ backgroundColor: "#000"}, 300 ); },
function() {
jQuery(this).stop(true, false);
$(this).animate({ backgroundColor: "#e2e2e2"}, 300 ); }
);
}
但当然不去了。唯一起作用的是,如果我更改 if () 中的“黑色”或其他任何东西,它在第二种翻转样式中表现良好。
任何想法 ?