私は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 () の「黒」を変更するか、他の何かを変更すると、2 番目のロールオーバー スタイルがうまくいくことです。
何か案が ?