jQueryでアコーディオンをやろうとしています。マウスオーバーすると、色がオレンジ色に変わりますが、背景画像も保持されます。マウスリーブでも同じことですが、うまくいきません。jQueryで複数の背景を追加するにはどうすればよいですか?
これは私が使用しているコードです:
$(".wrap-faq").on("mouseover", hoverFaq);
function hoverFaq() {
$(this).css("background", "#f7941e");
$(this).css("backgroundImage", "url(...img/bkg_leer_artic.png) center repeat");
}
$(".wrap-faq").on("mouseleave", unHoverFaq);
function unHoverFaq() {
$(this).css("background", "#e0e0e0");
$(this).css("backgroundImage", "url(...img/bkg_leer_artic.png) center repeat");
}
ボタンをクリックしたときにクラスを追加しようとしてactive
いるので、オレンジ色のままですが、これも機能しません。
jQuery:
$(".wrap-faq ").on("click", accordion);
function accordion() {
if (!$(this).hasClass("active")) {
$(".wrap-faq ").next().slideUp();
$(this).next().slideToggle();
$(".wrap-faq ").removeClass("active");
$(this).addClass("active");
}
}
CSS:
.active {
background:#f7941e url("../img/bkg_leer_artic.png") center repeat;
}
.wrap-faq {
background:#e0e0e0 url("../img/bkg_leer_artic.png") center repeat;
margin-bottom:2px;
cursor:pointer;
}
ここに私の JSFiddle があります: http://jsfiddle.net/xtatanx/3zvgY/5/